FIX: Bugs

This commit is contained in:
2025-04-19 23:33:11 +03:30
parent 6367325622
commit 0fe0587846
7 changed files with 52 additions and 23 deletions
+23 -12
View File
@@ -5,11 +5,15 @@ 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',
@@ -20,26 +24,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],
imageNames: [String],
mainImageNames: [String],
numId: {
type: Number,
unique: true,
},
mainImageUrl: String,
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 },
@@ -48,17 +59,17 @@ const belongingSchema = new mongoose.Schema(
}
)
belongingSchema.plugin(AutoIncrement, { inc_field: 'numId' })
belongingSchema.plugin(AutoIncrement, { inc_field: 'belongingCode' })
belongingSchema.methods.getDocumentsSignedUrls = async function () {
return getMultipleSignedUrls(this.documentNames, 'belonging-images')
belongingSchema.methods.getDocumentsSignedUrls = function () {
return getMultipleSignedUrls(this.documentNames, 'belonging-documents')
}
belongingSchema.methods.getImagesSignedUrls = async function () {
belongingSchema.methods.getImagesSignedUrls = function () {
return getMultipleSignedUrls(this.imageNames, 'belonging-images')
}
belongingSchema.methods.getMainImagedSignedUrl = async function () {
belongingSchema.methods.getMainImagedSignedUrl = function () {
return getMultipleSignedUrls(this.mainImageNames, 'belonging-images')
}