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