Merge branch 'main' into transaction
# Conflicts: # config/.env # package-lock.json # package.json # setup/routerEndpoints.js
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user