UPDATE: line in indexAllBelongings, collection name to belongings
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
const Belonging = require('./belongingModel')
|
const Belonging = require('./belongingModel')
|
||||||
const AppError = require('../../globalErrorHandler/AppError')
|
const AppError = require('../../globalErrorHandler/AppError')
|
||||||
const { client } = require('../../setup/typesense')
|
const { client } = require('../../setup/typesense')
|
||||||
const TsApiFeatures = require("../../utils/TsApiFeatures");
|
const TsApiFeatures = require('../../utils/TsApiFeatures')
|
||||||
|
|
||||||
const getAllBelongings = async () => {
|
const getAllBelongings = async () => {
|
||||||
return Belonging.find({}, null, null).populate('category')
|
return Belonging.find({}, null, null).populate('category')
|
||||||
@@ -29,7 +29,6 @@ const getBelonging = async (belongingId) => {
|
|||||||
belonging.signedImageUrls = imageUrls
|
belonging.signedImageUrls = imageUrls
|
||||||
belonging.signedMainImageUrls = mainImageUrls
|
belonging.signedMainImageUrls = mainImageUrls
|
||||||
|
|
||||||
|
|
||||||
return belonging
|
return belonging
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,9 +69,9 @@ const ensureCollectionExists = async () => {
|
|||||||
const searchBelongings = async (inputQuery) => {
|
const searchBelongings = async (inputQuery) => {
|
||||||
const tsFeatures = new TsApiFeatures(client, 'belongings', inputQuery).filter().facet().sort().limitFields().paginate().search()
|
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 indexAllBelongings = async () => {
|
||||||
const batchSize = 20
|
const batchSize = 20
|
||||||
@@ -92,28 +91,26 @@ const indexAllBelongings = async () => {
|
|||||||
let documents = []
|
let documents = []
|
||||||
|
|
||||||
for (const belonging of belongings) {
|
for (const belonging of belongings) {
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
_id: belonging._id,
|
_id: belonging._id,
|
||||||
isActive: belonging.isActive,
|
isActive: belonging.isActive,
|
||||||
belongingCode: belonging.belongingCode,
|
belongingCode: belonging.belongingCode,
|
||||||
category: belonging.category.map( x=> x.englishName),
|
category: belonging.category.map((x) => x.englishName),
|
||||||
nativeCategory: belonging.category.map( x=> x.nativeName),
|
nativeCategory: belonging.category.map((x) => x.nativeName),
|
||||||
documents: belonging.documents,
|
documents: belonging.documents,
|
||||||
description: belonging.description,
|
description: belonging.description,
|
||||||
coordinates: belonging.location.coordinates
|
coordinates: belonging.location.coordinates,
|
||||||
}
|
}
|
||||||
|
|
||||||
documents.push(data)
|
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 = () => {
|
const getTypeSenseSchema = () => {
|
||||||
return {
|
return {
|
||||||
name: 'belongings',
|
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 }
|
||||||
|
|||||||
Reference in New Issue
Block a user