feat(bucket): auto-create buckets and move files from temp to main buckets on property save
deploy-chabokan / deploy (push) Canceled after 0s
deploy-chabokan / deploy (push) Canceled after 0s
This commit is contained in:
@@ -4,12 +4,20 @@ const Building = require('./buildingModel')
|
||||
const AppError = require('../../globalErrorHandler/AppError')
|
||||
const { client } = require('../../setup/typesense')
|
||||
const TsApiFeatures = require('../../utils/TsApiFeatures')
|
||||
const { moveFromTempToMain } = require('../file/fileService')
|
||||
|
||||
const getAllProperties = async () => {
|
||||
return Property.find({}, null, null).populate('category').populate('status')
|
||||
}
|
||||
|
||||
const createProperty = async (data) => {
|
||||
if (data.mainImageUrls && Array.isArray(data.mainImageUrls) && data.mainImageUrls.length > 0) {
|
||||
data.mainImageUrls = await moveFromTempToMain(data.mainImageUrls, 'properties')
|
||||
}
|
||||
if (data.documentUrls && Array.isArray(data.documentUrls) && data.documentUrls.length > 0) {
|
||||
data.documentUrls = await moveFromTempToMain(data.documentUrls, 'documents')
|
||||
}
|
||||
|
||||
if (data.propertyType === 'Land' || data.propertyType === 'زمین') {
|
||||
return Land.create(data)
|
||||
} else if (data.propertyType === 'Building' || data.propertyType === 'ساختمان') {
|
||||
@@ -37,6 +45,13 @@ const getProperty = async (propertyId) => {
|
||||
}
|
||||
|
||||
const updateProperty = async (propertyId, data) => {
|
||||
if (data.mainImageUrls && Array.isArray(data.mainImageUrls) && data.mainImageUrls.length > 0) {
|
||||
data.mainImageUrls = await moveFromTempToMain(data.mainImageUrls, 'properties')
|
||||
}
|
||||
if (data.documentUrls && Array.isArray(data.documentUrls) && data.documentUrls.length > 0) {
|
||||
data.documentUrls = await moveFromTempToMain(data.documentUrls, 'documents')
|
||||
}
|
||||
|
||||
const property = await Property.findOneAndUpdate({ _id: propertyId }, data, { new: true })
|
||||
|
||||
if (!property) {
|
||||
|
||||
Reference in New Issue
Block a user