ADD: API_URL to env
ADD: DocumentUrls and mainImageUrls field in belonging model FIX: Indexing bugs for belonging ADD: getImage endpoint to get private images ADD: PrivateUrl field as virtual FIX: Minor bug in bucketDeleteFile service ADD: Word type to multer file checker
This commit is contained in:
@@ -35,10 +35,8 @@ const belongingSchema = new mongoose.Schema(
|
||||
required: false,
|
||||
},
|
||||
},
|
||||
documentNames: [String],
|
||||
imageNames: [String],
|
||||
mainImageNames: [String],
|
||||
mainImageUrl: String,
|
||||
documentUrls: [String],
|
||||
mainImageUrls: [String],
|
||||
tags: [String],
|
||||
isActive: {
|
||||
type: Boolean,
|
||||
@@ -66,15 +64,11 @@ const belongingSchema = new mongoose.Schema(
|
||||
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')
|
||||
return getMultipleSignedUrls(this.documentUrls, 'belonging-documents')
|
||||
}
|
||||
|
||||
belongingSchema.methods.getMainImagedSignedUrl = function () {
|
||||
return getMultipleSignedUrls(this.mainImageNames, 'belonging-images')
|
||||
return getMultipleSignedUrls(this.mainImageUrls, 'belonging-images')
|
||||
}
|
||||
|
||||
belongingSchema.index({ location: '2dsphere' }) // Enable geospatial queries
|
||||
|
||||
@@ -20,13 +20,11 @@ const getBelonging = async (belongingId) => {
|
||||
}
|
||||
|
||||
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
|
||||
@@ -91,18 +89,21 @@ const indexAllBelongings = async () => {
|
||||
let documents = []
|
||||
|
||||
for (const belonging of belongings) {
|
||||
const categoryArray = Array.isArray(belonging.category) ? belonging.category : belonging.category ? [belonging.category] : []
|
||||
const tags = belonging.tags.join(', ')
|
||||
|
||||
const combinedTags = belonging.tags.join(' ');
|
||||
|
||||
const data = {
|
||||
_id: belonging._id,
|
||||
name: belonging.name,
|
||||
isActive: belonging.isActive,
|
||||
belongingCode: belonging.belongingCode,
|
||||
category: categoryArray.map((x) => x.englishName),
|
||||
nativeCategory: categoryArray.map((x) => x.nativeName),
|
||||
name: belonging.name,
|
||||
category: belonging.category.englishName,
|
||||
nativeCategory: belonging.category.nativeName,
|
||||
imageUrl: belonging.mainImageUrls[0] || '',
|
||||
documents: belonging.documentUrls,
|
||||
description: belonging.description,
|
||||
unit: belonging.unit,
|
||||
tags: tags,
|
||||
tags: combinedTags,
|
||||
coordinates: belonging.location.coordinates,
|
||||
createdAt: Math.floor(new Date(belonging.createdAt).getTime() / 1000), // Store as timestamp in seconds
|
||||
}
|
||||
@@ -124,13 +125,14 @@ const getTypeSenseSchema = () => {
|
||||
{ name: '_id', type: 'string', facet: false, infix: false },
|
||||
{ name: 'name', type: 'string', facet: false, infix: true },
|
||||
{ name: 'belongingCode', type: 'int64', facet: false },
|
||||
{ name: 'category', type: 'string[]', facet: true, infix: true },
|
||||
{ name: 'nativeCategory', type: 'string[]', facet: false, infix: true },
|
||||
{ name: 'category', type: 'string', facet: true, infix: true },
|
||||
{ name: 'nativeCategory', type: 'string', facet: false, infix: true },
|
||||
{ name: 'description', type: 'string', facet: false },
|
||||
{ name: 'unit', type: 'string', facet: false, infix: true },
|
||||
{ name: 'tags', type: 'string', facet: false, infix: true },
|
||||
{ name: 'coordinates', type: 'geopoint' },
|
||||
{ name: 'createdAt', type: 'int64', facet: false },
|
||||
{ name: 'imageUrl', type: 'string', facet: false },
|
||||
],
|
||||
default_sorting_field: 'createdAt',
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user