From 5ce201c4e4409e0282d61074ba15dae93f57a387 Mon Sep 17 00:00:00 2001 From: MohammadHMazarei Date: Tue, 22 Apr 2025 12:58:25 +0330 Subject: [PATCH] UPDATE: line in indexAllBelongings, collection name to belongings --- components/belonging/belongingService.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/components/belonging/belongingService.js b/components/belonging/belongingService.js index bf889dc..055f94b 100644 --- a/components/belonging/belongingService.js +++ b/components/belonging/belongingService.js @@ -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} \ No newline at end of file +module.exports = { updateBelonging, indexAllBelongings, getBelonging, getAllBelongings, createBelonging, deleteBelonging, searchBelongings }