Merge branch 'main' into transaction

# Conflicts:
#	config/.env
#	package-lock.json
#	package.json
#	setup/routerEndpoints.js
This commit is contained in:
2025-04-19 23:37:59 +03:30
25 changed files with 2184 additions and 124 deletions
+32 -11
View File
@@ -1,14 +1,19 @@
const mongoose = require('mongoose')
const ObjectID = mongoose.Schema.Types.ObjectId
const AutoIncrement = require('mongoose-sequence')(mongoose)
const { getMultipleSignedUrls, getSignedUrl } = require('../file/fileService')
const belongingSchema = new mongoose.Schema(
{
belongingCode: {
name: {
type: String,
required: true,
unique: true,
},
belongingCode: {
type: Number,
unique: true,
},
category: {
type: ObjectID,
ref: 'Category',
@@ -23,29 +28,33 @@ const belongingSchema = new mongoose.Schema(
type: {
type: String,
enum: ['Point'], // GeoJSON type
required: true,
required: false,
},
coordinates: {
type: [Number], // Array of numbers: [longitude, latitude]
required: true,
required: false,
},
},
documentNames: [String],
documentUrls: [String],
imageNames: [String],
imageUrls: [String],
mainImageNames: [String],
mainImageUrl: String,
mainImageName: String,
numId: {
type: Number,
unique: true,
},
tags: [String],
isActive: {
type: Boolean,
default: true,
select: false,
},
features: [
{
definition: {
type: ObjectID,
ref: 'Feature',
required: true,
},
value: mongoose.Schema.Types.Mixed,
},
],
},
{
toJSON: { virtuals: true },
@@ -54,7 +63,19 @@ const belongingSchema = new mongoose.Schema(
}
)
belongingSchema.plugin(AutoIncrement, { inc_field: 'numId' })
belongingSchema.plugin(AutoIncrement, { inc_field: 'belongingCode' })
belongingSchema.methods.getDocumentsSignedUrls = function () {
return getMultipleSignedUrls(this.documentNames, 'belonging-documents')
}
belongingSchema.methods.getImagesSignedUrls = function () {
return getMultipleSignedUrls(this.imageNames, 'belonging-images')
}
belongingSchema.methods.getMainImagedSignedUrl = function () {
return getMultipleSignedUrls(this.mainImageNames, 'belonging-images')
}
belongingSchema.index({ location: '2dsphere' }) // Enable geospatial queries
+1 -1
View File
@@ -15,7 +15,7 @@ router.post('/admin/index-all', perm.requires('indexbelongings', belongingContro
router.get('/admin/get-one/:belongingId', perm.requires('getabelonging'), belongingController.getBelonging)
router.patch('/admin/update/:belongingId', perm.requires('updateabelonging'), belongingController.updateBelonging)
router.put('/admin/update/:belongingId', perm.requires('updateabelonging'), belongingController.updateBelonging)
router.delete('/admin/delete/:belongingId', perm.requires('deleteabelonging'), belongingController.deleteBelonging)
+15 -3
View File
@@ -4,20 +4,32 @@ const { client } = require('../../setup/typesense')
const TsApiFeatures = require("../../utils/TsApiFeatures");
const getAllBelongings = async () => {
return Belonging.find({}, null, null)
return Belonging.find({}, null, null).populate('category')
}
const createBelonging = async (data) => {
console.log(data)
return Belonging.create(data, null)
}
const getBelonging = async (belongingId) => {
const belonging = await Belonging.findById(belongingId, null, null)
let belonging = await Belonging.findById(belongingId, null, null)
if (!belonging) {
throw new AppError('NoBelongingFound', 404, {})
}
const documentUrls = await belonging.getDocumentsSignedUrls()
const imageUrls = await belonging.getImagesSignedUrls()
const mainImageUrls = await belonging.getMainImagedSignedUrl()
belonging = JSON.parse(JSON.stringify(belonging))
belonging.signedDocumentUrls = documentUrls
belonging.signedImageUrls = imageUrls
belonging.signedMainImageUrls = mainImageUrls
return belonging
}
@@ -120,4 +132,4 @@ const getTypeSenseSchema = () => {
}
}
module.exports = {indexAllBelongings, getBelonging, getAllBelongings, createBelonging, deleteBelonging, searchBelongings}
module.exports = {updateBelonging, indexAllBelongings, getBelonging, getAllBelongings, createBelonging, deleteBelonging, searchBelongings}