FIX: Bugs

This commit is contained in:
2025-04-19 23:33:11 +03:30
parent 6367325622
commit 0fe0587846
7 changed files with 52 additions and 23 deletions
+23 -12
View File
@@ -5,11 +5,15 @@ const { getMultipleSignedUrls, getSignedUrl } = require('../file/fileService')
const belongingSchema = new mongoose.Schema( const belongingSchema = new mongoose.Schema(
{ {
belongingCode: { name: {
type: String, type: String,
required: true, required: true,
unique: true, unique: true,
}, },
belongingCode: {
type: Number,
unique: true,
},
category: { category: {
type: ObjectID, type: ObjectID,
ref: 'Category', ref: 'Category',
@@ -20,26 +24,33 @@ const belongingSchema = new mongoose.Schema(
type: { type: {
type: String, type: String,
enum: ['Point'], // GeoJSON type enum: ['Point'], // GeoJSON type
required: true, required: false,
}, },
coordinates: { coordinates: {
type: [Number], // Array of numbers: [longitude, latitude] type: [Number], // Array of numbers: [longitude, latitude]
required: true, required: false,
}, },
}, },
documentNames: [String], documentNames: [String],
imageNames: [String], imageNames: [String],
mainImageNames: [String], mainImageNames: [String],
numId: { mainImageUrl: String,
type: Number,
unique: true,
},
tags: [String], tags: [String],
isActive: { isActive: {
type: Boolean, type: Boolean,
default: true, default: true,
select: false, select: false,
}, },
features: [
{
definition: {
type: ObjectID,
ref: 'Feature',
required: true,
},
value: mongoose.Schema.Types.Mixed,
},
],
}, },
{ {
toJSON: { virtuals: true }, toJSON: { virtuals: true },
@@ -48,17 +59,17 @@ const belongingSchema = new mongoose.Schema(
} }
) )
belongingSchema.plugin(AutoIncrement, { inc_field: 'numId' }) belongingSchema.plugin(AutoIncrement, { inc_field: 'belongingCode' })
belongingSchema.methods.getDocumentsSignedUrls = async function () { belongingSchema.methods.getDocumentsSignedUrls = function () {
return getMultipleSignedUrls(this.documentNames, 'belonging-images') return getMultipleSignedUrls(this.documentNames, 'belonging-documents')
} }
belongingSchema.methods.getImagesSignedUrls = async function () { belongingSchema.methods.getImagesSignedUrls = function () {
return getMultipleSignedUrls(this.imageNames, 'belonging-images') return getMultipleSignedUrls(this.imageNames, 'belonging-images')
} }
belongingSchema.methods.getMainImagedSignedUrl = async function () { belongingSchema.methods.getMainImagedSignedUrl = function () {
return getMultipleSignedUrls(this.mainImageNames, 'belonging-images') return getMultipleSignedUrls(this.mainImageNames, 'belonging-images')
} }
+1 -1
View File
@@ -15,7 +15,7 @@ router.post('/admin/index-all', perm.requires('indexbelongings', belongingContro
router.get('/admin/get-one/:belongingId', perm.requires('getabelonging'), belongingController.getBelonging) router.get('/admin/get-one/:belongingId', perm.requires('getabelonging'), belongingController.getBelonging)
router.patch('/admin/update/:belongingId', perm.requires('updateabelonging'), belongingController.updateBelonging) router.put('/admin/update/:belongingId', perm.requires('updateabelonging'), belongingController.updateBelonging)
router.delete('/admin/delete/:belongingId', perm.requires('deleteabelonging'), belongingController.deleteBelonging) router.delete('/admin/delete/:belongingId', perm.requires('deleteabelonging'), belongingController.deleteBelonging)
+11 -6
View File
@@ -4,25 +4,30 @@ 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) return Belonging.find({}, null, null).populate('category')
} }
const createBelonging = async (data) => { const createBelonging = async (data) => {
console.log(data)
return Belonging.create(data, null) return Belonging.create(data, null)
} }
const getBelonging = async (belongingId) => { const getBelonging = async (belongingId) => {
const belonging = await Belonging.findById(belongingId, null, null).lean() let belonging = await Belonging.findById(belongingId, null, null)
if (!belonging) { if (!belonging) {
throw new AppError('NoBelongingFound', 404, {}) throw new AppError('NoBelongingFound', 404, {})
} }
const documentUrls = await belonging.getDocumentsSignedUrls()
const imageUrls = await belonging.getImagesSignedUrls()
const mainImageUrls = await belonging.getMainImagedSignedUrl()
belonging.signedDocumentUrls = belonging.getDocumentsSignedUrls() belonging = JSON.parse(JSON.stringify(belonging))
belonging.signedImageUrls = belonging.getImagesSignedUrls()
belonging.signedMainImageUrls = belonging.getMainImagedSignedUrl()
belonging.signedDocumentUrls = documentUrls
belonging.signedImageUrls = imageUrls
belonging.signedMainImageUrls = mainImageUrls
return belonging return belonging
@@ -127,4 +132,4 @@ const getTypeSenseSchema = () => {
} }
} }
module.exports = {indexAllBelongings, getBelonging, getAllBelongings, createBelonging, deleteBelonging, searchBelongings} module.exports = {updateBelonging, indexAllBelongings, getBelonging, getAllBelongings, createBelonging, deleteBelonging, searchBelongings}
+1 -1
View File
@@ -106,7 +106,7 @@ const getSignedUrl = async (fileName, bucketName) => {
const getMultipleSignedUrls = async (fileNameArray, bucketName) => { const getMultipleSignedUrls = async (fileNameArray, bucketName) => {
const urls = [] const urls = []
for (let fileName of fileNameArray) { for (let fileName of fileNameArray) {
urls.push({ url: await getSignedUrl(fileName, bucketName)}) urls.push({ url: await getSignedUrl(fileName, bucketName), fileName: fileName})
} }
return urls return urls
} }
+13
View File
@@ -0,0 +1,13 @@
MONGODB_URL=mongodb://admin:*135792468*@localhost:27018/marbm?authSource=admin
NODE_ENV=development
PORT=3000
JWT_SECRET=Y@RJNS@MPL!
REDIS_URL= redis://:135792468@localhost:6379/0
LOGIN_ATTEMPT_LIMIT=10
SUPER_ADMIN_ROLE_ID=66a2da5b9b989a8909948848
TYPE_SENSE_URL=localhost:8108
TYPE_SENSE_API_KEY=vYd7pTgaoRy
AWS_ENDPOINT=localhost:8001
AWS_ACCESS_KEY=EFYrmV0EiasdtbhJygNglaCZYtti
AWS_SECRET_KEY=ArkI5GDTIdaKFSp54lrx78gSW1
AWS_REGION=default
+1 -1
View File
@@ -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'] const types = ['png', 'jpg', 'jpeg', 'webp', 'pdf', 'doc', 'docx', 'xlsx', 'dwg']
const formatsText = types.join(' - ') const formatsText = types.join(' - ')
const fileFilter = (req, file, cb) => { const fileFilter = (req, file, cb) => {
+2 -2
View File
@@ -19,7 +19,7 @@ const requires = (...permissions) => {
if ( if (
!checker(rolePerm, perm?._id) && !checker(rolePerm, perm?._id) &&
!checker(userPerm, perm?._id) && !checker(userPerm, perm?._id) &&
role._id.toString() !== process.env.SUPER_ADMIN_ID role._id.toString() !== process.env.SUPER_ADMIN_ROLE_ID
) { ) {
throw new AppError('NoPermissionAccess', 403, {}) throw new AppError('NoPermissionAccess', 403, {})
} }
@@ -50,7 +50,7 @@ const adminCheck = () => {
if ( if (
!checker(rolePerm, perm?._id) && !checker(rolePerm, perm?._id) &&
!checker(userPerm, perm?._id) && !checker(userPerm, perm?._id) &&
user.role?._id.toString() !== process.env.SUPER_ADMIN_ID user.role?._id.toString() !== process.env.SUPER_ADMIN_ROLE_ID
) { ) {
throw new AppError('NoPermissionAccess', 403, {}) throw new AppError('NoPermissionAccess', 403, {})
} }