ADD: Server urls
ADD: SearchBelongings function REMOVE: API from docker compose (run it manually) ADD: Required packages REMOVE: Redundant import from TsApiFeatures
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
const catchAsync = require('../../globalErrorHandler/catchAsync')
|
||||
const belongingService = require('./belongingService')
|
||||
|
||||
exports.searchBelongings = catchAsync(async (req, res, next) => {
|
||||
const {facets, belongings, totalCount, pagesCount} = await belongingService.searchBelongings()
|
||||
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
facets, belongings, totalCount, pagesCount
|
||||
})
|
||||
})
|
||||
|
||||
exports.indexAllBelongings = catchAsync(async (req, res, next) => {
|
||||
const { indexedCount } = await belongingService.indexAllBelongings()
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Belonging = require('./belongingModel')
|
||||
const AppError = require('../../globalErrorHandler/AppError')
|
||||
const { client } = require('../../setup/typesense')
|
||||
const TsApiFeatures = require("../../utils/TsApiFeatures");
|
||||
|
||||
const getAllBelongings = async () => {
|
||||
return Belonging.find({}, null, null)
|
||||
@@ -53,15 +54,23 @@ const ensureCollectionExists = async () => {
|
||||
await client.collections().create(schema)
|
||||
console.log('Collection "belongings" created successfully')
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
return {facets, belongings: items, totalCount, pagesCount}
|
||||
}
|
||||
const indexAllBelongings = async () => {
|
||||
const batchSize = 20
|
||||
const count = await Product.countDocuments({isTrash: false, isActive: true, isHidden: false}, null)
|
||||
const count = await Belonging.countDocuments({}, null)
|
||||
const rounds = Math.ceil(count / batchSize)
|
||||
|
||||
await ensureCollectionExists()
|
||||
|
||||
for (let i = 1; i <= rounds; i++) {
|
||||
console.log(`Indexing ${batchSize} products, Round ${i}`)
|
||||
console.log(`Indexing ${batchSize} belongings, Round ${i}`)
|
||||
|
||||
const belongings = await Belonging.find({}, null, null)
|
||||
.populate('category')
|
||||
@@ -111,4 +120,4 @@ const getTypeSenseSchema = () => {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {indexAllBelongings, getBelonging, getAllBelongings, createBelonging, deleteBelonging}
|
||||
module.exports = {indexAllBelongings, getBelonging, getAllBelongings, createBelonging, deleteBelonging, searchBelongings}
|
||||
+5
-3
@@ -1,7 +1,9 @@
|
||||
MONGODB_URL=mongodb://admin:password@mongodb:27018/marbm?authSource=admin
|
||||
MONGODB_URL=mongodb://admin:*135792468*@localhost:27018/marbm?authSource=admin
|
||||
NODE_ENV=development
|
||||
PORT=3000
|
||||
JWT_SECRET=Y@RJ$WT!@K0NS@MPL!
|
||||
REDIS_URL= redis://:135792468@redis:6379/0
|
||||
REDIS_URL= redis://:135792468@localhost:6379/0
|
||||
LOGIN_ATTEMPT_LIMIT=5
|
||||
SUPER_ADMIN_ROLE_ID=676afd6d076b286f9395b05f
|
||||
SUPER_ADMIN_ROLE_ID=676afd6d076b286f9395b05f
|
||||
TYPE_SENSE_URL=localhost:8108
|
||||
TYPE_SENSE_API_KEY=vYQq7pTgl6ACoRy
|
||||
+13
-14
@@ -1,14 +1,14 @@
|
||||
services:
|
||||
api-server:
|
||||
build: ./
|
||||
ports:
|
||||
- 3000:3000
|
||||
environment:
|
||||
- MONGODB_URL=mongodb://admin:*135792468*@mongo:27017/marbm?authSource=admin
|
||||
- NODE_ENV=development
|
||||
- PORT=3000
|
||||
- REDIS_URL=redis://:135792468@redis:6379/0
|
||||
minio-server:
|
||||
# api-server:
|
||||
# build: ./
|
||||
# ports:
|
||||
# - 3000:3000
|
||||
# environment:
|
||||
# - MONGODB_URL=mongodb://admin:*135792468*@mongo:27017/marbm?authSource=admin
|
||||
# - NODE_ENV=development
|
||||
# - PORT=3000
|
||||
# - REDIS_URL=redis://:135792468@redis:6379/0
|
||||
bm_minio:
|
||||
image: minio/minio
|
||||
ports:
|
||||
- 9000:9000
|
||||
@@ -19,7 +19,7 @@ services:
|
||||
volumes:
|
||||
- bm_minio:/upload/
|
||||
command: server /data --console-address ":9001"
|
||||
mongo:
|
||||
bm_mongo:
|
||||
image: mongo:8.0
|
||||
ports:
|
||||
- 27018:27017
|
||||
@@ -30,7 +30,7 @@ services:
|
||||
volumes:
|
||||
- bm_mongo:/data/db
|
||||
|
||||
redis:
|
||||
bm_redis:
|
||||
image: redis
|
||||
command: redis-server --save 20 1 --loglevel warning --requirepass 135792468
|
||||
volumes:
|
||||
@@ -38,8 +38,7 @@ services:
|
||||
ports:
|
||||
- 6379:6379
|
||||
|
||||
typesense:
|
||||
container_name: typesense
|
||||
bm_typesense:
|
||||
image: typesense/typesense:27.1
|
||||
command: ./typesense-server
|
||||
ports:
|
||||
|
||||
Generated
+121
@@ -9,6 +9,7 @@
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.9",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"body-parser": "^1.20.3",
|
||||
"chalk": "^5.3.0",
|
||||
@@ -21,12 +22,25 @@
|
||||
"mongoose": "^8.9.0",
|
||||
"mongoose-sequence": "^6.0.1",
|
||||
"redis": "^4.7.0",
|
||||
"typesense": "^1.8.2",
|
||||
"validator": "^13.12.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^3.1.9"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/runtime": {
|
||||
"version": "7.26.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.26.0.tgz",
|
||||
"integrity": "sha512-FDSOghenHTiToteC/QRlv2q3DhPZ/oOXTBoirfWNx1Cx3TMVcGWQtMMmQcSvb/JjpNeGzx8Pq/b4fKEJuWm1sw==",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"regenerator-runtime": "^0.14.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@mongodb-js/saslprep": {
|
||||
"version": "1.1.9",
|
||||
"resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.9.tgz",
|
||||
@@ -144,6 +158,21 @@
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz",
|
||||
"integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA=="
|
||||
},
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.7.9",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz",
|
||||
"integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.6",
|
||||
"form-data": "^4.0.0",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/balanced-match": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||
@@ -303,6 +332,17 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"dependencies": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/compressible": {
|
||||
"version": "2.0.18",
|
||||
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
|
||||
@@ -401,6 +441,14 @@
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/depd": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
||||
@@ -585,6 +633,38 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.15.9",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
|
||||
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"debug": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/form-data": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz",
|
||||
"integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==",
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/forwarded": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
||||
@@ -888,6 +968,18 @@
|
||||
"resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz",
|
||||
"integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg=="
|
||||
},
|
||||
"node_modules/loglevel": {
|
||||
"version": "1.9.2",
|
||||
"resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.9.2.tgz",
|
||||
"integrity": "sha512-HgMmCqIJSAKqo68l0rS2AanEWfkxaZ5wNiEFb5ggm08lDs9Xl2KxBlX3PTcaD2chBM1gXAYf491/M2Rv8Jwayg==",
|
||||
"engines": {
|
||||
"node": ">= 0.6.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "tidelift",
|
||||
"url": "https://tidelift.com/funding/github/npm/loglevel"
|
||||
}
|
||||
},
|
||||
"node_modules/math-intrinsics": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.0.0.tgz",
|
||||
@@ -1255,6 +1347,11 @@
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/proxy-from-env": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
||||
},
|
||||
"node_modules/pstree.remy": {
|
||||
"version": "1.1.8",
|
||||
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz",
|
||||
@@ -1321,6 +1418,9 @@
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/redis/-/redis-4.7.0.tgz",
|
||||
"integrity": "sha512-zvmkHEAdGMn+hMRXuMBtu4Vo5P6rHQjLoHftu+lBqq8ZTA3RCVC/WzD790bkKKiNFp7d5/9PcSD19fJyyRvOdQ==",
|
||||
"workspaces": [
|
||||
"./packages/*"
|
||||
],
|
||||
"dependencies": {
|
||||
"@redis/bloom": "1.2.0",
|
||||
"@redis/client": "1.6.0",
|
||||
@@ -1330,6 +1430,12 @@
|
||||
"@redis/time-series": "1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/regenerator-runtime": {
|
||||
"version": "0.14.1",
|
||||
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz",
|
||||
"integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==",
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/safe-buffer": {
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
||||
@@ -1585,6 +1691,21 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/typesense": {
|
||||
"version": "1.8.2",
|
||||
"resolved": "https://registry.npmjs.org/typesense/-/typesense-1.8.2.tgz",
|
||||
"integrity": "sha512-aBpePjA99Qvo+OP2pJwMpvga4Jrm1Y2oV5NsrWXBxlqUDNEUCPZBIksPv2Hq0jxQxHhLLyJVbjXjByXsvpCDVA==",
|
||||
"dependencies": {
|
||||
"axios": "^1.6.0",
|
||||
"loglevel": "^1.8.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/runtime": "^7.23.2"
|
||||
}
|
||||
},
|
||||
"node_modules/undefsafe": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz",
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.9",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"body-parser": "^1.20.3",
|
||||
"chalk": "^5.3.0",
|
||||
@@ -23,6 +24,7 @@
|
||||
"mongoose": "^8.9.0",
|
||||
"mongoose-sequence": "^6.0.1",
|
||||
"redis": "^4.7.0",
|
||||
"typesense": "^1.8.2",
|
||||
"validator": "^13.12.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const axios = require('axios')
|
||||
const { fi } = require('@faker-js/faker')
|
||||
class TsApiFeatures {
|
||||
constructor(client, collectionName, queryString) {
|
||||
this.client = client
|
||||
|
||||
Reference in New Issue
Block a user