@@ -2,11 +2,14 @@ const catchAsync = require('../../globalErrorHandler/catchAsync')
|
|||||||
const belongingService = require('./belongingService')
|
const belongingService = require('./belongingService')
|
||||||
|
|
||||||
exports.searchBelongings = catchAsync(async (req, res, next) => {
|
exports.searchBelongings = catchAsync(async (req, res, next) => {
|
||||||
const {facets, belongings, totalCount, pagesCount} = await belongingService.searchBelongings()
|
const { facets, belongings, totalCount, pagesCount } = await belongingService.searchBelongings(req.query)
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
status: 'success',
|
status: 'success',
|
||||||
facets, belongings, totalCount, pagesCount
|
facets,
|
||||||
|
belongings,
|
||||||
|
totalCount,
|
||||||
|
pagesCount,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -15,11 +18,10 @@ exports.indexAllBelongings = catchAsync(async (req, res, next) => {
|
|||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
status: 'success',
|
status: 'success',
|
||||||
indexedCount
|
indexedCount,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
exports.getAllBelongings = catchAsync(async (req, res, next) => {
|
exports.getAllBelongings = catchAsync(async (req, res, next) => {
|
||||||
const belongings = await belongingService.getAllBelongings()
|
const belongings = await belongingService.getAllBelongings()
|
||||||
|
|
||||||
|
|||||||
@@ -35,10 +35,8 @@ const belongingSchema = new mongoose.Schema(
|
|||||||
required: false,
|
required: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
documentNames: [String],
|
documentUrls: [String],
|
||||||
imageNames: [String],
|
mainImageUrls: [String],
|
||||||
mainImageNames: [String],
|
|
||||||
mainImageUrl: String,
|
|
||||||
tags: [String],
|
tags: [String],
|
||||||
isActive: {
|
isActive: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
@@ -66,15 +64,11 @@ const belongingSchema = new mongoose.Schema(
|
|||||||
belongingSchema.plugin(AutoIncrement, { inc_field: 'belongingCode' })
|
belongingSchema.plugin(AutoIncrement, { inc_field: 'belongingCode' })
|
||||||
|
|
||||||
belongingSchema.methods.getDocumentsSignedUrls = function () {
|
belongingSchema.methods.getDocumentsSignedUrls = function () {
|
||||||
return getMultipleSignedUrls(this.documentNames, 'belonging-documents')
|
return getMultipleSignedUrls(this.documentUrls, 'belonging-documents')
|
||||||
}
|
|
||||||
|
|
||||||
belongingSchema.methods.getImagesSignedUrls = function () {
|
|
||||||
return getMultipleSignedUrls(this.imageNames, 'belonging-images')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
belongingSchema.methods.getMainImagedSignedUrl = function () {
|
belongingSchema.methods.getMainImagedSignedUrl = function () {
|
||||||
return getMultipleSignedUrls(this.mainImageNames, 'belonging-images')
|
return getMultipleSignedUrls(this.mainImageUrls, 'belonging-images')
|
||||||
}
|
}
|
||||||
|
|
||||||
belongingSchema.index({ location: '2dsphere' }) // Enable geospatial queries
|
belongingSchema.index({ location: '2dsphere' }) // Enable geospatial queries
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ router.get('/admin/get-all', perm.requires('getallbelongings'), belongingControl
|
|||||||
|
|
||||||
router.post('/admin/create', perm.requires('createabelonging'), belongingController.createBelonging)
|
router.post('/admin/create', perm.requires('createabelonging'), belongingController.createBelonging)
|
||||||
|
|
||||||
router.post('/admin/index-all', perm.requires('indexbelongings', belongingController.indexAllBelongings))
|
router.post('/admin/index-all', perm.requires('indexbelongings'), belongingController.indexAllBelongings)
|
||||||
|
|
||||||
|
router.get('/admin/search', perm.requires('searchbelongings'), belongingController.searchBelongings)
|
||||||
|
|
||||||
router.get('/admin/get-one/:belongingId', perm.requires('getabelonging'), belongingController.getBelonging)
|
router.get('/admin/get-one/:belongingId', perm.requires('getabelonging'), belongingController.getBelonging)
|
||||||
|
|
||||||
|
|||||||
@@ -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')
|
||||||
@@ -20,16 +20,13 @@ const getBelonging = async (belongingId) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const documentUrls = await belonging.getDocumentsSignedUrls()
|
const documentUrls = await belonging.getDocumentsSignedUrls()
|
||||||
const imageUrls = await belonging.getImagesSignedUrls()
|
|
||||||
const mainImageUrls = await belonging.getMainImagedSignedUrl()
|
const mainImageUrls = await belonging.getMainImagedSignedUrl()
|
||||||
|
|
||||||
belonging = JSON.parse(JSON.stringify(belonging))
|
belonging = JSON.parse(JSON.stringify(belonging))
|
||||||
|
|
||||||
belonging.signedDocumentUrls = documentUrls
|
belonging.signedDocumentUrls = documentUrls
|
||||||
belonging.signedImageUrls = imageUrls
|
|
||||||
belonging.signedMainImageUrls = mainImageUrls
|
belonging.signedMainImageUrls = mainImageUrls
|
||||||
|
|
||||||
|
|
||||||
return belonging
|
return belonging
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,9 +67,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
|
||||||
@@ -93,43 +90,52 @@ const indexAllBelongings = async () => {
|
|||||||
|
|
||||||
for (const belonging of belongings) {
|
for (const belonging of belongings) {
|
||||||
|
|
||||||
|
const combinedTags = belonging.tags.join(' ');
|
||||||
|
|
||||||
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),
|
name: belonging.name,
|
||||||
nativeCategory: belonging.category.map( x=> x.nativeName),
|
category: belonging.category.englishName,
|
||||||
documents: belonging.documents,
|
nativeCategory: belonging.category.nativeName,
|
||||||
|
imageUrl: belonging.mainImageUrls[0] || '',
|
||||||
|
documents: belonging.documentUrls,
|
||||||
description: belonging.description,
|
description: belonging.description,
|
||||||
coordinates: belonging.location.coordinates
|
unit: belonging.unit,
|
||||||
|
tags: combinedTags,
|
||||||
|
coordinates: belonging.location.coordinates,
|
||||||
|
createdAt: Math.floor(new Date(belonging.createdAt).getTime() / 1000), // Store as timestamp in seconds
|
||||||
}
|
}
|
||||||
|
|
||||||
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',
|
||||||
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: 'isActive', type: 'bool', facet: false, infix: true },
|
{ name: 'name', type: 'string', facet: false, infix: true },
|
||||||
{ name: 'belongingCode', type: 'string', facet: true },
|
{ name: 'belongingCode', type: 'int64', facet: false },
|
||||||
{ name: 'category', type: 'string[]', facet: true },
|
{ name: 'category', type: 'string', facet: true, infix: true },
|
||||||
{ name: 'nativeCategory', type: 'string[]', facet: false },
|
{ name: 'nativeCategory', type: 'string', facet: false, infix: true },
|
||||||
{ name: 'documents', type: 'string[]', facet: false },
|
|
||||||
{ name: 'description', type: 'string', facet: false },
|
{ name: 'description', type: 'string', facet: false },
|
||||||
|
{ name: 'unit', type: 'string', facet: false, infix: true },
|
||||||
|
{ name: 'tags', type: 'string', facet: false, infix: true },
|
||||||
{ name: 'coordinates', type: 'geopoint' },
|
{ name: 'coordinates', type: 'geopoint' },
|
||||||
|
{ name: 'createdAt', type: 'int64', facet: false },
|
||||||
|
{ name: 'imageUrl', type: 'string', facet: false },
|
||||||
],
|
],
|
||||||
default_sorting_field: 'createdAt',
|
default_sorting_field: 'createdAt',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {updateBelonging, indexAllBelongings, getBelonging, getAllBelongings, createBelonging, deleteBelonging, searchBelongings}
|
module.exports = { updateBelonging, indexAllBelongings, getBelonging, getAllBelongings, createBelonging, deleteBelonging, searchBelongings }
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ exports.bucketSingleUpload = catchAsync(async (req, res, next) => {
|
|||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
status: 'success',
|
status: 'success',
|
||||||
data: fileData,
|
data: fileData,
|
||||||
|
bucketName: req.params.bucketName,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ exports.bucketMultiUpload = catchAsync(async (req, res, next) => {
|
|||||||
status: 'success',
|
status: 'success',
|
||||||
results: files.length,
|
results: files.length,
|
||||||
data: files,
|
data: files,
|
||||||
|
bucketName: req.params.bucketName,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -49,11 +51,31 @@ exports.getSignedUrl = catchAsync(async (req, res, next) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
exports.getImage = catchAsync(async (req, res, next) => {
|
||||||
|
const { bucketName, fileName } = req.params;
|
||||||
|
|
||||||
|
const imageData = await fileService.getImage(bucketName, fileName);
|
||||||
|
|
||||||
|
|
||||||
|
if (!imageData) {
|
||||||
|
return res.status(404).json({
|
||||||
|
status: 'fail',
|
||||||
|
message: 'Image not found'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set appropriate headers for the image response
|
||||||
|
res.set('Content-Type', imageData.contentType);
|
||||||
|
|
||||||
|
res.send(imageData.buffer);
|
||||||
|
});
|
||||||
|
|
||||||
exports.bucketDeleteFile = catchAsync(async (req, res, next) => {
|
exports.bucketDeleteFile = catchAsync(async (req, res, next) => {
|
||||||
await fileService.bucketDeleteFile(req.body, req.params.bucketName)
|
const { fileName } = await fileService.bucketDeleteFile(req.body, req.params.bucketName)
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
status: 'success',
|
status: 'success',
|
||||||
|
data: fileName,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -28,5 +28,9 @@ fileSchema.virtual('publicUrl').get(function () {
|
|||||||
return this.fileEndpoint + '/' + this.bucketName + '/' + this.fileName
|
return this.fileEndpoint + '/' + this.bucketName + '/' + this.fileName
|
||||||
})
|
})
|
||||||
|
|
||||||
|
fileSchema.virtual('privateUrl').get(function () {
|
||||||
|
return process.env.API_URL + '/api/files/get-image/' + this.bucketName + '/' + this.fileName
|
||||||
|
})
|
||||||
|
|
||||||
const File = mongoose.model('file', fileSchema)
|
const File = mongoose.model('file', fileSchema)
|
||||||
module.exports = File
|
module.exports = File
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ router.get('/bucket/get-files', perm.requires('getbucketfiles'), fileController.
|
|||||||
|
|
||||||
router.get('/bucket/get-signed', perm.requires('getbucketfiles'), fileController.getSignedUrl)
|
router.get('/bucket/get-signed', perm.requires('getbucketfiles'), fileController.getSignedUrl)
|
||||||
|
|
||||||
|
router.get('/get-image/:bucketName/:fileName', perm.requires('getimages'), fileController.getImage);
|
||||||
|
|
||||||
router.delete('/bucket/delete-file/:bucketName', perm.requires('deletebucketfiles'), fileController.bucketDeleteFile)
|
router.delete('/bucket/delete-file/:bucketName', perm.requires('deletebucketfiles'), fileController.bucketDeleteFile)
|
||||||
|
|
||||||
router.get('/admin/get-all', perm.requires('getallfiles'), fileController.getAllFiles)
|
router.get('/admin/get-all', perm.requires('getallfiles'), fileController.getAllFiles)
|
||||||
|
|||||||
@@ -52,10 +52,20 @@ const bucketMultiUpload = async (files, bucketName) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bucketDeleteFile = async (fileName, bucketName) => {
|
const bucketDeleteFile = async (fileName, bucketName) => {
|
||||||
await deleteObject(fileName, bucketName)
|
let exportedFileName = getLastUrlSegment(fileName)
|
||||||
await deleteFile(fileName)
|
await deleteObject(exportedFileName, bucketName)
|
||||||
|
await deleteFile(exportedFileName)
|
||||||
|
|
||||||
return null
|
return { fileName }
|
||||||
|
}
|
||||||
|
|
||||||
|
const getLastUrlSegment = (url) => {
|
||||||
|
if (!url.includes('/')) {
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
const cleanUrl = url.endsWith('/') ? url.slice(0, -1) : url
|
||||||
|
const segments = cleanUrl.split('/')
|
||||||
|
return segments[segments.length - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
const getAllFiles = async () => {
|
const getAllFiles = async () => {
|
||||||
@@ -100,6 +110,7 @@ const getSignedUrl = async (fileName, bucketName) => {
|
|||||||
if (!fileName) {
|
if (!fileName) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
console.log(bucketName,fileName)
|
||||||
return signedUrl(bucketName, fileName)
|
return signedUrl(bucketName, fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +131,39 @@ const moveFromTempToMain = async (files, targetBucket) => {
|
|||||||
await removeObject(tempBucket, file)
|
await removeObject(tempBucket, file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getImage = async (bucketName, fileName) => {
|
||||||
|
if (!fileName) {
|
||||||
|
throw new AppError('NoFileFound', 404, {})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Get signed URL from the file service
|
||||||
|
const signedUrl = await getSignedUrl(fileName, bucketName);
|
||||||
|
|
||||||
|
if (!signedUrl) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch the image from the signed URL
|
||||||
|
const response = await fetch(signedUrl);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new AppError('NoFileFound', 404, {})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the content type from the response headers
|
||||||
|
const contentType = response.headers.get('content-type');
|
||||||
|
|
||||||
|
// Convert the response to a buffer
|
||||||
|
const buffer = await response.arrayBuffer();
|
||||||
|
|
||||||
|
// Return both the buffer and content type
|
||||||
|
return {
|
||||||
|
buffer: Buffer.from(buffer),
|
||||||
|
contentType
|
||||||
|
};
|
||||||
|
};
|
||||||
module.exports = {
|
module.exports = {
|
||||||
moveFromTempToMain,
|
moveFromTempToMain,
|
||||||
getMultipleSignedUrls,
|
getMultipleSignedUrls,
|
||||||
@@ -133,4 +177,5 @@ module.exports = {
|
|||||||
bucketMultiUpload,
|
bucketMultiUpload,
|
||||||
bucketDeleteFile,
|
bucketDeleteFile,
|
||||||
bucketGetFiles,
|
bucketGetFiles,
|
||||||
|
getImage,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,27 @@
|
|||||||
const catchAsync = require('../../globalErrorHandler/catchAsync')
|
const catchAsync = require('../../globalErrorHandler/catchAsync')
|
||||||
const transactionService = require('./transactionService')
|
const transactionService = require('./transactionService')
|
||||||
|
|
||||||
|
exports.searchTransactions = catchAsync(async (req, res, next) => {
|
||||||
|
const { facets, transactions, totalCount, pagesCount } = await transactionService.searchTransactions(req.query)
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
status: 'success',
|
||||||
|
facets,
|
||||||
|
transactions,
|
||||||
|
totalCount,
|
||||||
|
pagesCount,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
exports.indexAllTransactions = catchAsync(async (req, res, next) => {
|
||||||
|
const { indexedCount } = await transactionService.indexAllTransactions()
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
status: 'success',
|
||||||
|
indexedCount,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
exports.createTransaction = catchAsync(async (req, res, next) => {
|
exports.createTransaction = catchAsync(async (req, res, next) => {
|
||||||
const transactions = await transactionService.createTransaction(req.body)
|
const transactions = await transactionService.createTransaction(req.body)
|
||||||
|
|
||||||
|
|||||||
@@ -19,14 +19,26 @@ router.post(
|
|||||||
transactionController.createTransaction
|
transactionController.createTransaction
|
||||||
)
|
)
|
||||||
|
|
||||||
|
router.post(
|
||||||
|
'/admin/index-all',
|
||||||
|
// perm.requires('getallbelongings'),
|
||||||
|
transactionController.indexAllTransactions
|
||||||
|
)
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
'/admin/belonging/:belongingId/inventory',
|
'/admin/search',
|
||||||
|
// perm.requires('getallbelongings'),
|
||||||
|
transactionController.searchTransactions
|
||||||
|
)
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/admin/get-stock-by-belonging/:belongingId',
|
||||||
// perm.requires('getallbelongings'),
|
// perm.requires('getallbelongings'),
|
||||||
transactionController.getBelongingInventory
|
transactionController.getBelongingInventory
|
||||||
)
|
)
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
'/admin/belonging/:belongingId',
|
'/admin/get-all-by-belonging/:belongingId',
|
||||||
// perm.requires('getallbelongings'),
|
// perm.requires('getallbelongings'),
|
||||||
transactionController.getTransactionByBelongingId
|
transactionController.getTransactionByBelongingId
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ const getBelongingInventory = async (belongingId) => {
|
|||||||
const result = await Transaction.aggregate([
|
const result = await Transaction.aggregate([
|
||||||
{
|
{
|
||||||
$match: {
|
$match: {
|
||||||
belongingId: ObjectID,
|
belongingId: belonging._id,
|
||||||
$or: [{ status: 'finished' }, { status: 'pending' }],
|
$or: [{ status: 'finished' }, { status: 'pending' }],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -151,6 +151,81 @@ const deleteTransaction = async (transactionId) => {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ensureCollectionExists = async () => {
|
||||||
|
const collections = await client.collections().retrieve()
|
||||||
|
const collectionExists = collections.some((collection) => collection.name === 'transactions')
|
||||||
|
|
||||||
|
if (collectionExists) {
|
||||||
|
await client.collections('transactions').delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
const schema = getTypeSenseSchema()
|
||||||
|
|
||||||
|
await client.collections().create(schema)
|
||||||
|
console.log('Collection "transactions" created successfully')
|
||||||
|
}
|
||||||
|
|
||||||
|
const searchTransactions = async (inputQuery) => {
|
||||||
|
const tsFeatures = new TsApiFeatures(client, 'transactions', inputQuery).filter().facet().sort().limitFields().paginate().search()
|
||||||
|
|
||||||
|
let { facets, items, totalCount, pagesCount } = await tsFeatures.execute()
|
||||||
|
|
||||||
|
return { facets, transactions: items, totalCount, pagesCount }
|
||||||
|
}
|
||||||
|
|
||||||
|
const indexAllTransactions = async () => {
|
||||||
|
const batchSize = 20
|
||||||
|
const count = await Transaction.countDocuments({}, null)
|
||||||
|
const rounds = Math.ceil(count / batchSize)
|
||||||
|
|
||||||
|
await ensureCollectionExists()
|
||||||
|
|
||||||
|
for (let i = 1; i <= rounds; i++) {
|
||||||
|
console.log(`Indexing ${batchSize} transactions, Round ${i}`)
|
||||||
|
|
||||||
|
const transactions = await Transaction.find({}, null, null)
|
||||||
|
.skip((i - 1) * batchSize)
|
||||||
|
.limit(batchSize)
|
||||||
|
|
||||||
|
let documents = []
|
||||||
|
|
||||||
|
for (const transaction of transactions) {
|
||||||
|
const data = {
|
||||||
|
_id: transaction._id,
|
||||||
|
type: transaction.type,
|
||||||
|
status: transaction.status,
|
||||||
|
source: transaction.source,
|
||||||
|
value: transaction.value,
|
||||||
|
description: transaction.description,
|
||||||
|
createdAt: Math.floor(new Date(transaction.createdAt).getTime() / 1000), // Store as timestamp in seconds
|
||||||
|
}
|
||||||
|
|
||||||
|
documents.push(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
await client.collections('transactions').documents().import(documents, { action: 'emplace' })
|
||||||
|
}
|
||||||
|
|
||||||
|
return { totalCount: count }
|
||||||
|
}
|
||||||
|
|
||||||
|
const getTypeSenseSchema = () => {
|
||||||
|
return {
|
||||||
|
name: 'transactions',
|
||||||
|
enable_nested_fields: true,
|
||||||
|
fields: [
|
||||||
|
{ name: '_id', type: 'string', facet: false, infix: false },
|
||||||
|
{ name: 'type', type: 'string', facet: false },
|
||||||
|
{ name: 'status', type: 'string', facet: false },
|
||||||
|
{ name: 'source', type: 'string', facet: false },
|
||||||
|
{ name: 'value', type: 'int64', facet: false },
|
||||||
|
{ name: 'description', type: 'string', facet: false, infix: true },
|
||||||
|
{ name: 'createdAt', type: 'int64', facet: false },
|
||||||
|
],
|
||||||
|
default_sorting_field: 'createdAt',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
createTransaction,
|
createTransaction,
|
||||||
getUserTransaction,
|
getUserTransaction,
|
||||||
@@ -158,4 +233,6 @@ module.exports = {
|
|||||||
updateTransaction,
|
updateTransaction,
|
||||||
deleteTransaction,
|
deleteTransaction,
|
||||||
getTransactionByBelongingId,
|
getTransactionByBelongingId,
|
||||||
|
indexAllTransactions,
|
||||||
|
searchTransactions,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ const userSchema = new mongoose.Schema(
|
|||||||
role: {
|
role: {
|
||||||
type: ObjectID,
|
type: ObjectID,
|
||||||
ref: 'Role',
|
ref: 'Role',
|
||||||
|
required: true
|
||||||
},
|
},
|
||||||
isAdmin: {
|
isAdmin: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ const loginCheck = require('../../middlewares/loginCheck')
|
|||||||
const router = new express.Router()
|
const router = new express.Router()
|
||||||
|
|
||||||
router.post('/signup-email', userController.signup)
|
router.post('/signup-email', userController.signup)
|
||||||
|
|
||||||
router.post('/login-email', userController.loginUser)
|
router.post('/login-email', userController.loginUser)
|
||||||
|
|
||||||
router.post('/logout', userController.logoutUser)
|
router.post('/logout', userController.logoutUser)
|
||||||
|
|
||||||
router.use(loginCheck.loginProtect)
|
router.use(loginCheck.loginProtect)
|
||||||
|
|||||||
+8
-6
@@ -5,9 +5,11 @@ JWT_SECRET=Y@RJ$WT!@K0NS@MPL!
|
|||||||
REDIS_URL= redis://:GFis6zU4DXW9Q7NQ@services.irn12.chabokan.net:19794/0
|
REDIS_URL= redis://:GFis6zU4DXW9Q7NQ@services.irn12.chabokan.net:19794/0
|
||||||
LOGIN_ATTEMPT_LIMIT=900
|
LOGIN_ATTEMPT_LIMIT=900
|
||||||
SUPER_ADMIN_ROLE_ID=66a2da5b9b989a8909948848
|
SUPER_ADMIN_ROLE_ID=66a2da5b9b989a8909948848
|
||||||
TYPE_SENSE_URL=services.irn9.chabokan.net
|
TYPE_SENSE_URL=bm-typesense.chbk.app
|
||||||
TYPE_SENSE_API_KEY=zQzlsVKmSX5M0N09
|
TYPE_SENSE_API_KEY=rHV4vZePdfBYFC9q
|
||||||
AWS_ENDPOINT=bm-minio.chbk.app
|
AWS_ENDPOINT=bm-minio-2.chbk.app
|
||||||
AWS_ACCESS_KEY=EFYrmV0EiH4qwGERtbhJygNglaCZYtti
|
AWS_URL=https://bm-minio-2.chbk.app
|
||||||
AWS_SECRET_KEY=ArkI5GDTId6GsQ0WvKFSp54lrx78gSW1
|
AWS_ACCESS_KEY=lwcAHMbCea4jeKMtj6SOjMtmETY93rBb
|
||||||
AWS_REGION=default
|
AWS_SECRET_KEY=xXKrceoCV3Wx35d0JmULgNvHJ0UlTQnO
|
||||||
|
AWS_REGION=default
|
||||||
|
API_URL=http://localhost:3000
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
const multer = require('multer')
|
const multer = require('multer')
|
||||||
const AppError = require('../globalErrorHandler/AppError')
|
const AppError = require('../globalErrorHandler/AppError')
|
||||||
|
|
||||||
const types = ['png', 'jpg', 'jpeg', 'webp', 'pdf', 'doc', 'docx', 'xlsx', 'dwg']
|
const types = ['png', 'jpg', 'jpeg', 'webp', 'pdf', 'doc', 'docx', 'xlsx', 'dwg', 'vnd.openxmlformats-officedocument.wordprocessingml.document']
|
||||||
const formatsText = types.join(' - ')
|
const formatsText = types.join(' - ')
|
||||||
|
|
||||||
const fileFilter = (req, file, cb) => {
|
const fileFilter = (req, file, cb) => {
|
||||||
|
|||||||
+2
-2
@@ -23,9 +23,9 @@
|
|||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"minio": "^8.0.3",
|
"minio": "^8.0.3",
|
||||||
"mongoose": "^8.9.0",
|
"mongoose": "^8.9.0",
|
||||||
"mongoose-sequence": "^6.0.1",
|
"mongoose-sequence": "^6.0.1",
|
||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
"redis": "^4.7.0",
|
"redis": "^4.7.0",
|
||||||
"typesense": "^1.8.2",
|
"typesense": "^1.8.2",
|
||||||
"validator": "^13.12.0"
|
"validator": "^13.12.0"
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ let client = new TypeSense.Client({
|
|||||||
{
|
{
|
||||||
host: process.env.TYPE_SENSE_URL,
|
host: process.env.TYPE_SENSE_URL,
|
||||||
port: '443',
|
port: '443',
|
||||||
protocol: 'httpS',
|
protocol: 'https',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
apiKey: process.env.TYPE_SENSE_API_KEY,
|
apiKey: process.env.TYPE_SENSE_API_KEY,
|
||||||
|
|||||||
Reference in New Issue
Block a user