@iservice365/module-hygiene 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -299,6 +299,7 @@ declare function useSupplyRepository(): {
|
|
|
299
299
|
createUniqueIndex: () => Promise<void>;
|
|
300
300
|
createSupply: (value: TSupplyCreate, session?: ClientSession) => Promise<ObjectId>;
|
|
301
301
|
getSupplies: ({ page, limit, search, site, }: TGetSupplysQuery) => Promise<{}>;
|
|
302
|
+
getSupplyById: (_id: string | ObjectId) => Promise<{}>;
|
|
302
303
|
updateSupply: (_id: string | ObjectId, value: TSupplyUpdate, session?: ClientSession) => Promise<number>;
|
|
303
304
|
deleteSupply: (_id: string | ObjectId, session?: ClientSession) => Promise<number>;
|
|
304
305
|
};
|
|
@@ -306,6 +307,7 @@ declare function useSupplyRepository(): {
|
|
|
306
307
|
declare function useSupplyController(): {
|
|
307
308
|
createSupply: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
308
309
|
getSupplies: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
310
|
+
getSupplyById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
309
311
|
updateSupply: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
310
312
|
deleteSupply: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
311
313
|
};
|
package/dist/index.js
CHANGED
|
@@ -2962,6 +2962,48 @@ function useSupplyRepository() {
|
|
|
2962
2962
|
throw error;
|
|
2963
2963
|
}
|
|
2964
2964
|
}
|
|
2965
|
+
async function getSupplyById(_id) {
|
|
2966
|
+
try {
|
|
2967
|
+
_id = new import_mongodb10.ObjectId(_id);
|
|
2968
|
+
} catch (error) {
|
|
2969
|
+
throw new import_node_server_utils17.BadRequestError("Invalid supply ID format.");
|
|
2970
|
+
}
|
|
2971
|
+
const query = {
|
|
2972
|
+
_id,
|
|
2973
|
+
status: { $ne: "deleted" }
|
|
2974
|
+
};
|
|
2975
|
+
const cacheKey = (0, import_node_server_utils17.makeCacheKey)(namespace_collection, {
|
|
2976
|
+
_id: _id.toString()
|
|
2977
|
+
});
|
|
2978
|
+
const cachedData = await getCache(cacheKey);
|
|
2979
|
+
if (cachedData) {
|
|
2980
|
+
import_node_server_utils17.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
2981
|
+
return cachedData;
|
|
2982
|
+
}
|
|
2983
|
+
try {
|
|
2984
|
+
const data = await collection.aggregate([
|
|
2985
|
+
{ $match: query },
|
|
2986
|
+
{
|
|
2987
|
+
$project: {
|
|
2988
|
+
name: 1,
|
|
2989
|
+
unitOfMeasurement: 1,
|
|
2990
|
+
qty: 1
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
]).toArray();
|
|
2994
|
+
if (!data || data.length === 0) {
|
|
2995
|
+
throw new import_node_server_utils17.NotFoundError("Supply not found.");
|
|
2996
|
+
}
|
|
2997
|
+
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
2998
|
+
import_node_server_utils17.logger.info(`Cache set for key: ${cacheKey}`);
|
|
2999
|
+
}).catch((err) => {
|
|
3000
|
+
import_node_server_utils17.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
3001
|
+
});
|
|
3002
|
+
return data[0];
|
|
3003
|
+
} catch (error) {
|
|
3004
|
+
throw error;
|
|
3005
|
+
}
|
|
3006
|
+
}
|
|
2965
3007
|
async function updateSupply(_id, value, session) {
|
|
2966
3008
|
try {
|
|
2967
3009
|
_id = new import_mongodb10.ObjectId(_id);
|
|
@@ -3034,6 +3076,7 @@ function useSupplyRepository() {
|
|
|
3034
3076
|
createUniqueIndex,
|
|
3035
3077
|
createSupply,
|
|
3036
3078
|
getSupplies,
|
|
3079
|
+
getSupplyById,
|
|
3037
3080
|
updateSupply,
|
|
3038
3081
|
deleteSupply
|
|
3039
3082
|
};
|
|
@@ -3046,6 +3089,7 @@ function useSupplyController() {
|
|
|
3046
3089
|
const {
|
|
3047
3090
|
createSupply: _createSupply,
|
|
3048
3091
|
getSupplies: _getSupplies,
|
|
3092
|
+
getSupplyById: _getSupplyById,
|
|
3049
3093
|
updateSupply: _updateSupply,
|
|
3050
3094
|
deleteSupply: _deleteSupply
|
|
3051
3095
|
} = useSupplyRepository();
|
|
@@ -3100,6 +3144,25 @@ function useSupplyController() {
|
|
|
3100
3144
|
return;
|
|
3101
3145
|
}
|
|
3102
3146
|
}
|
|
3147
|
+
async function getSupplyById(req, res, next) {
|
|
3148
|
+
const validation = import_joi10.default.string().hex().required();
|
|
3149
|
+
const _id = req.params.id;
|
|
3150
|
+
const { error } = validation.validate(_id);
|
|
3151
|
+
if (error) {
|
|
3152
|
+
import_node_server_utils18.logger.log({ level: "error", message: error.message });
|
|
3153
|
+
next(new import_node_server_utils18.BadRequestError(error.message));
|
|
3154
|
+
return;
|
|
3155
|
+
}
|
|
3156
|
+
try {
|
|
3157
|
+
const data = await _getSupplyById(_id);
|
|
3158
|
+
res.json(data);
|
|
3159
|
+
return;
|
|
3160
|
+
} catch (error2) {
|
|
3161
|
+
import_node_server_utils18.logger.log({ level: "error", message: error2.message });
|
|
3162
|
+
next(error2);
|
|
3163
|
+
return;
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3103
3166
|
async function updateSupply(req, res, next) {
|
|
3104
3167
|
const payload = { id: req.params.id, ...req.body };
|
|
3105
3168
|
const validation = import_joi10.default.object({
|
|
@@ -3149,6 +3212,7 @@ function useSupplyController() {
|
|
|
3149
3212
|
return {
|
|
3150
3213
|
createSupply,
|
|
3151
3214
|
getSupplies,
|
|
3215
|
+
getSupplyById,
|
|
3152
3216
|
updateSupply,
|
|
3153
3217
|
deleteSupply
|
|
3154
3218
|
};
|