ADD: Description to belongingModel
ADD: Typesense Index All function
This commit is contained in:
@@ -9,15 +9,11 @@ const belongingSchema = new mongoose.Schema(
|
||||
required: true,
|
||||
unique: true,
|
||||
},
|
||||
belongingCategory: {
|
||||
category: {
|
||||
type: ObjectID,
|
||||
ref: 'Category',
|
||||
},
|
||||
projectCode: {
|
||||
type: String,
|
||||
required: true,
|
||||
default: false,
|
||||
},
|
||||
description: String,
|
||||
relatedProjects: [String],
|
||||
location: {
|
||||
type: {
|
||||
|
||||
@@ -2,15 +2,15 @@ const Belonging = require('./belongingModel')
|
||||
const AppError = require('../../globalErrorHandler/AppError')
|
||||
const { client } = require('../../setup/typesense')
|
||||
|
||||
module.exports.getAllBelongings = async () => {
|
||||
const getAllBelongings = async () => {
|
||||
return Belonging.find({}, null, null)
|
||||
}
|
||||
|
||||
module.exports.createBelonging = async (data) => {
|
||||
const createBelonging = async (data) => {
|
||||
return Belonging.create(data, null)
|
||||
}
|
||||
|
||||
module.exports.getBelonging = async (belongingId) => {
|
||||
const getBelonging = async (belongingId) => {
|
||||
const belonging = await Belonging.findById(belongingId, null, null)
|
||||
|
||||
if (!belonging) {
|
||||
@@ -20,7 +20,7 @@ module.exports.getBelonging = async (belongingId) => {
|
||||
return belonging
|
||||
}
|
||||
|
||||
module.exports.updateBelonging = async (belongingId, data) => {
|
||||
const updateBelonging = async (belongingId, data) => {
|
||||
const belonging = await Belonging.findOneAndUpdate({ _id: belongingId }, data, { new: true })
|
||||
|
||||
if (!belonging) {
|
||||
@@ -30,7 +30,7 @@ module.exports.updateBelonging = async (belongingId, data) => {
|
||||
return belonging
|
||||
}
|
||||
|
||||
module.exports.deleteBelonging = async (belongingId) => {
|
||||
const deleteBelonging = async (belongingId) => {
|
||||
const belonging = await Belonging.findByIdAndUpdate(belongingId, { isActive: false }, { new: true })
|
||||
|
||||
if (!belonging) {
|
||||
@@ -73,12 +73,14 @@ const indexAllBelongings = async () => {
|
||||
for (const belonging of belongings) {
|
||||
|
||||
const data = {
|
||||
}
|
||||
|
||||
for (let feature of product.features) {
|
||||
if (feature.definition && feature.value) {
|
||||
data[feature.definition.englishName] = feature.value
|
||||
}
|
||||
_id: belonging._id,
|
||||
isActive: belonging.isActive,
|
||||
belongingCode: belonging.belongingCode,
|
||||
category: belonging.category.map( x=> x.englishName),
|
||||
nativeCategory: belonging.category.map( x=> x.nativeName),
|
||||
documents: belonging.documents,
|
||||
description: belonging.description,
|
||||
coordinates: belonging.location.coordinates
|
||||
}
|
||||
|
||||
documents.push(data)
|
||||
@@ -97,7 +99,7 @@ const getTypeSenseSchema = () => {
|
||||
enable_nested_fields: true,
|
||||
fields: [
|
||||
{ name: '_id', type: 'string', facet: false, infix: false },
|
||||
{ name: 'projectCode', type: 'string', facet: false, infix: true },
|
||||
{ name: 'isActive', type: 'bool', facet: false, infix: true },
|
||||
{ name: 'belongingCode', type: 'string', facet: true },
|
||||
{ name: 'category', type: 'string[]', facet: true },
|
||||
{ name: 'nativeCategory', type: 'string[]', facet: false },
|
||||
@@ -107,4 +109,6 @@ const getTypeSenseSchema = () => {
|
||||
],
|
||||
default_sorting_field: 'createdAt',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {indexAllBelongings, getBelonging, getAllBelongings, createBelonging, deleteBelonging}
|
||||
Reference in New Issue
Block a user