UPDATE: line in indexAllBelongings, collection name to belongings

This commit is contained in:
MohammadHMazarei
2025-04-22 12:58:25 +03:30
parent 1ae70dda18
commit 5ce201c4e4
+9 -12
View File
@@ -1,7 +1,7 @@
const Belonging = require('./belongingModel')
const AppError = require('../../globalErrorHandler/AppError')
const { client } = require('../../setup/typesense')
const TsApiFeatures = require("../../utils/TsApiFeatures");
const TsApiFeatures = require('../../utils/TsApiFeatures')
const getAllBelongings = async () => {
return Belonging.find({}, null, null).populate('category')
@@ -29,7 +29,6 @@ const getBelonging = async (belongingId) => {
belonging.signedImageUrls = imageUrls
belonging.signedMainImageUrls = mainImageUrls
return belonging
}
@@ -70,9 +69,9 @@ const ensureCollectionExists = async () => {
const searchBelongings = async (inputQuery) => {
const tsFeatures = new TsApiFeatures(client, 'belongings', inputQuery).filter().facet().sort().limitFields().paginate().search()
let {facets, items, totalCount, pagesCount} = await tsFeatures.execute()
let { facets, items, totalCount, pagesCount } = await tsFeatures.execute()
return {facets, belongings: items, totalCount, pagesCount}
return { facets, belongings: items, totalCount, pagesCount }
}
const indexAllBelongings = async () => {
const batchSize = 20
@@ -92,28 +91,26 @@ const indexAllBelongings = async () => {
let documents = []
for (const belonging of belongings) {
const data = {
_id: belonging._id,
isActive: belonging.isActive,
belongingCode: belonging.belongingCode,
category: belonging.category.map( x=> x.englishName),
nativeCategory: belonging.category.map( x=> x.nativeName),
category: belonging.category.map((x) => x.englishName),
nativeCategory: belonging.category.map((x) => x.nativeName),
documents: belonging.documents,
description: belonging.description,
coordinates: belonging.location.coordinates
coordinates: belonging.location.coordinates,
}
documents.push(data)
}
await client.collections('belonging').documents().import(documents, {action: 'emplace'})
await client.collections('belongings').documents().import(documents, { action: 'emplace' })
}
return {totalCount: count}
return { totalCount: count }
}
const getTypeSenseSchema = () => {
return {
name: 'belongings',
@@ -132,4 +129,4 @@ const getTypeSenseSchema = () => {
}
}
module.exports = {updateBelonging, indexAllBelongings, getBelonging, getAllBelongings, createBelonging, deleteBelonging, searchBelongings}
module.exports = { updateBelonging, indexAllBelongings, getBelonging, getAllBelongings, createBelonging, deleteBelonging, searchBelongings }