@goweekdays/core 2.1.2 → 2.1.3
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 -1
- package/dist/index.js +419 -413
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +393 -387
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6877,259 +6877,27 @@ function useAppRepo() {
|
|
|
6877
6877
|
}
|
|
6878
6878
|
|
|
6879
6879
|
// src/resources/app/app.service.ts
|
|
6880
|
-
var
|
|
6881
|
-
var init2 = false;
|
|
6882
|
-
function useAppService() {
|
|
6883
|
-
const {
|
|
6884
|
-
updateById: _updateById,
|
|
6885
|
-
getById: _getById,
|
|
6886
|
-
deleteById: _deleteById,
|
|
6887
|
-
getByCode: _getByCode,
|
|
6888
|
-
add: _add
|
|
6889
|
-
} = useAppRepo();
|
|
6890
|
-
async function addDefaultApps() {
|
|
6891
|
-
const apps = [
|
|
6892
|
-
{
|
|
6893
|
-
code: "admin",
|
|
6894
|
-
name: "Admin",
|
|
6895
|
-
description: "Administrative application.",
|
|
6896
|
-
type: "default"
|
|
6897
|
-
},
|
|
6898
|
-
{
|
|
6899
|
-
code: "marketplace",
|
|
6900
|
-
name: "Marketplace",
|
|
6901
|
-
description: "Marketplace for product listings."
|
|
6902
|
-
},
|
|
6903
|
-
{
|
|
6904
|
-
code: "service",
|
|
6905
|
-
name: "Services",
|
|
6906
|
-
description: "Service offerings and management."
|
|
6907
|
-
},
|
|
6908
|
-
{
|
|
6909
|
-
code: "stay",
|
|
6910
|
-
name: "Stay",
|
|
6911
|
-
description: "Accommodation and lodging services."
|
|
6912
|
-
},
|
|
6913
|
-
{ code: "eat", name: "Eat", description: "Food and dining services." },
|
|
6914
|
-
{
|
|
6915
|
-
code: "experience",
|
|
6916
|
-
name: "Experience",
|
|
6917
|
-
description: "Experiential touring, travel, activities and events."
|
|
6918
|
-
},
|
|
6919
|
-
{
|
|
6920
|
-
code: "ride",
|
|
6921
|
-
name: "Ride",
|
|
6922
|
-
description: "Transportation and ride services."
|
|
6923
|
-
}
|
|
6924
|
-
];
|
|
6925
|
-
const session = import_utils40.useAtlas.getClient()?.startSession();
|
|
6926
|
-
if (!session) {
|
|
6927
|
-
throw new Error("Failed to start database session.");
|
|
6928
|
-
}
|
|
6929
|
-
try {
|
|
6930
|
-
session?.startTransaction();
|
|
6931
|
-
for (const app of apps) {
|
|
6932
|
-
const existingApp = await _getByCode(app.code);
|
|
6933
|
-
if (!existingApp) {
|
|
6934
|
-
await _add(app, session);
|
|
6935
|
-
}
|
|
6936
|
-
}
|
|
6937
|
-
await session.commitTransaction();
|
|
6938
|
-
import_utils40.logger.log({
|
|
6939
|
-
level: "info",
|
|
6940
|
-
message: "Default apps added successfully."
|
|
6941
|
-
});
|
|
6942
|
-
return;
|
|
6943
|
-
} catch (error) {
|
|
6944
|
-
await session.abortTransaction();
|
|
6945
|
-
import_utils40.logger.log({
|
|
6946
|
-
level: "error",
|
|
6947
|
-
message: `Failed to add default apps: ${error}`
|
|
6948
|
-
});
|
|
6949
|
-
throw error;
|
|
6950
|
-
} finally {
|
|
6951
|
-
await session.endSession();
|
|
6952
|
-
}
|
|
6953
|
-
}
|
|
6954
|
-
if (!init2) {
|
|
6955
|
-
addDefaultApps().catch((error) => {
|
|
6956
|
-
import_utils40.logger.log({
|
|
6957
|
-
level: "error",
|
|
6958
|
-
message: `Error in addDefaultApps: ${error}`
|
|
6959
|
-
});
|
|
6960
|
-
});
|
|
6961
|
-
init2 = true;
|
|
6962
|
-
}
|
|
6963
|
-
async function deleteById(id) {
|
|
6964
|
-
try {
|
|
6965
|
-
await _deleteById(id);
|
|
6966
|
-
return "App deleted successfully.";
|
|
6967
|
-
} catch (error) {
|
|
6968
|
-
throw error;
|
|
6969
|
-
}
|
|
6970
|
-
}
|
|
6971
|
-
return {
|
|
6972
|
-
deleteById
|
|
6973
|
-
};
|
|
6974
|
-
}
|
|
6975
|
-
|
|
6976
|
-
// src/resources/app/app.controller.ts
|
|
6977
|
-
var import_utils41 = require("@goweekdays/utils");
|
|
6978
|
-
var import_joi21 = __toESM(require("joi"));
|
|
6979
|
-
function useAppController() {
|
|
6980
|
-
const {
|
|
6981
|
-
getAll: _getAll,
|
|
6982
|
-
getById: _getById,
|
|
6983
|
-
add: _add,
|
|
6984
|
-
updateById: _updateById
|
|
6985
|
-
} = useAppRepo();
|
|
6986
|
-
const { deleteById: _deleteById } = useAppService();
|
|
6987
|
-
async function add(req, res, next) {
|
|
6988
|
-
const value = req.body;
|
|
6989
|
-
const { error } = schemaApp.validate(value);
|
|
6990
|
-
if (error) {
|
|
6991
|
-
next(new import_utils41.BadRequestError(error.message));
|
|
6992
|
-
return;
|
|
6993
|
-
}
|
|
6994
|
-
try {
|
|
6995
|
-
const result = await _add(value);
|
|
6996
|
-
res.json(result);
|
|
6997
|
-
return;
|
|
6998
|
-
} catch (error2) {
|
|
6999
|
-
next(error2);
|
|
7000
|
-
}
|
|
7001
|
-
}
|
|
7002
|
-
async function updateById(req, res, next) {
|
|
7003
|
-
const id = req.params.id ?? "";
|
|
7004
|
-
const { error: errorId } = import_joi21.default.string().hex().required().validate(id);
|
|
7005
|
-
if (errorId) {
|
|
7006
|
-
next(new import_utils41.BadRequestError(errorId.message));
|
|
7007
|
-
return;
|
|
7008
|
-
}
|
|
7009
|
-
const value = req.body;
|
|
7010
|
-
const { error } = schemaAppUpdate.validate(value);
|
|
7011
|
-
if (error) {
|
|
7012
|
-
next(new import_utils41.BadRequestError(error.message));
|
|
7013
|
-
return;
|
|
7014
|
-
}
|
|
7015
|
-
try {
|
|
7016
|
-
const result = await _updateById(req.params.id, value);
|
|
7017
|
-
res.json(result);
|
|
7018
|
-
return;
|
|
7019
|
-
} catch (error2) {
|
|
7020
|
-
next(error2);
|
|
7021
|
-
}
|
|
7022
|
-
}
|
|
7023
|
-
async function getAll(req, res, next) {
|
|
7024
|
-
const query = req.query;
|
|
7025
|
-
const validation = import_joi21.default.object({
|
|
7026
|
-
page: import_joi21.default.number().min(1).optional().allow("", null),
|
|
7027
|
-
limit: import_joi21.default.number().min(1).optional().allow("", null),
|
|
7028
|
-
search: import_joi21.default.string().optional().allow("", null),
|
|
7029
|
-
status: import_joi21.default.string().optional().allow("", null),
|
|
7030
|
-
type: import_joi21.default.string().optional().allow("", null)
|
|
7031
|
-
});
|
|
7032
|
-
const { error } = validation.validate(query);
|
|
7033
|
-
if (error) {
|
|
7034
|
-
next(new import_utils41.BadRequestError(error.message));
|
|
7035
|
-
return;
|
|
7036
|
-
}
|
|
7037
|
-
const page = parseInt(req.query.page) ?? 1;
|
|
7038
|
-
let limit = parseInt(req.query.limit) ?? 20;
|
|
7039
|
-
limit = isNaN(limit) ? 20 : limit;
|
|
7040
|
-
const sort = req.query.sort ? String(req.query.sort).split(",") : "";
|
|
7041
|
-
const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
|
|
7042
|
-
const sortObj = {};
|
|
7043
|
-
if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
|
|
7044
|
-
sort.forEach((field, index) => {
|
|
7045
|
-
sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
|
|
7046
|
-
});
|
|
7047
|
-
}
|
|
7048
|
-
const status = req.query.status ?? "active";
|
|
7049
|
-
const search = req.query.search ?? "";
|
|
7050
|
-
let type = req.query.type ? req.query.type.split(",") : "standard";
|
|
7051
|
-
try {
|
|
7052
|
-
const buildings = await _getAll({
|
|
7053
|
-
page,
|
|
7054
|
-
limit,
|
|
7055
|
-
sort: sortObj,
|
|
7056
|
-
status,
|
|
7057
|
-
search,
|
|
7058
|
-
type
|
|
7059
|
-
});
|
|
7060
|
-
res.json(buildings);
|
|
7061
|
-
return;
|
|
7062
|
-
} catch (error2) {
|
|
7063
|
-
next(error2);
|
|
7064
|
-
}
|
|
7065
|
-
}
|
|
7066
|
-
async function getById(req, res, next) {
|
|
7067
|
-
const id = req.params.id;
|
|
7068
|
-
const validation = import_joi21.default.object({
|
|
7069
|
-
id: import_joi21.default.string().hex().required()
|
|
7070
|
-
});
|
|
7071
|
-
const { error } = validation.validate({ id });
|
|
7072
|
-
if (error) {
|
|
7073
|
-
next(new import_utils41.BadRequestError(error.message));
|
|
7074
|
-
return;
|
|
7075
|
-
}
|
|
7076
|
-
try {
|
|
7077
|
-
const data = await _getById(id);
|
|
7078
|
-
res.json({
|
|
7079
|
-
message: "Successfully retrieved app.",
|
|
7080
|
-
data
|
|
7081
|
-
});
|
|
7082
|
-
return;
|
|
7083
|
-
} catch (error2) {
|
|
7084
|
-
next(error2);
|
|
7085
|
-
}
|
|
7086
|
-
}
|
|
7087
|
-
async function deleteById(req, res, next) {
|
|
7088
|
-
const id = req.params.id;
|
|
7089
|
-
const validation = import_joi21.default.object({
|
|
7090
|
-
id: import_joi21.default.string().hex().required()
|
|
7091
|
-
});
|
|
7092
|
-
const { error } = validation.validate({ id });
|
|
7093
|
-
if (error) {
|
|
7094
|
-
next(new import_utils41.BadRequestError(error.message));
|
|
7095
|
-
return;
|
|
7096
|
-
}
|
|
7097
|
-
try {
|
|
7098
|
-
const message = await _deleteById(id);
|
|
7099
|
-
res.json(message);
|
|
7100
|
-
return;
|
|
7101
|
-
} catch (error2) {
|
|
7102
|
-
next(error2);
|
|
7103
|
-
}
|
|
7104
|
-
}
|
|
7105
|
-
return {
|
|
7106
|
-
add,
|
|
7107
|
-
updateById,
|
|
7108
|
-
getAll,
|
|
7109
|
-
getById,
|
|
7110
|
-
deleteById
|
|
7111
|
-
};
|
|
7112
|
-
}
|
|
6880
|
+
var import_utils47 = require("@goweekdays/utils");
|
|
7113
6881
|
|
|
7114
6882
|
// src/resources/permission/permission.model.ts
|
|
7115
|
-
var
|
|
7116
|
-
var
|
|
7117
|
-
var schemaPermission =
|
|
7118
|
-
app:
|
|
7119
|
-
key:
|
|
7120
|
-
group:
|
|
7121
|
-
description:
|
|
7122
|
-
deprecated:
|
|
6883
|
+
var import_utils40 = require("@goweekdays/utils");
|
|
6884
|
+
var import_joi21 = __toESM(require("joi"));
|
|
6885
|
+
var schemaPermission = import_joi21.default.object({
|
|
6886
|
+
app: import_joi21.default.string().required(),
|
|
6887
|
+
key: import_joi21.default.string().required(),
|
|
6888
|
+
group: import_joi21.default.string().required(),
|
|
6889
|
+
description: import_joi21.default.string().required(),
|
|
6890
|
+
deprecated: import_joi21.default.boolean().optional().allow(null)
|
|
7123
6891
|
});
|
|
7124
|
-
var schemaPermissionUpdate =
|
|
7125
|
-
key:
|
|
7126
|
-
group:
|
|
7127
|
-
description:
|
|
6892
|
+
var schemaPermissionUpdate = import_joi21.default.object({
|
|
6893
|
+
key: import_joi21.default.string().optional().allow("", null),
|
|
6894
|
+
group: import_joi21.default.string().optional().allow("", null),
|
|
6895
|
+
description: import_joi21.default.string().max(1024).optional().allow("", null)
|
|
7128
6896
|
});
|
|
7129
6897
|
function modelPermission(value) {
|
|
7130
6898
|
const { error } = schemaPermission.validate(value);
|
|
7131
6899
|
if (error) {
|
|
7132
|
-
throw new
|
|
6900
|
+
throw new import_utils40.BadRequestError(error.message);
|
|
7133
6901
|
}
|
|
7134
6902
|
return {
|
|
7135
6903
|
_id: value._id,
|
|
@@ -7146,17 +6914,17 @@ function modelPermission(value) {
|
|
|
7146
6914
|
}
|
|
7147
6915
|
|
|
7148
6916
|
// src/resources/permission/permission.repository.ts
|
|
7149
|
-
var
|
|
6917
|
+
var import_utils41 = require("@goweekdays/utils");
|
|
7150
6918
|
var import_mongodb20 = require("mongodb");
|
|
7151
|
-
var
|
|
6919
|
+
var import_joi22 = __toESM(require("joi"));
|
|
7152
6920
|
function usePermissionRepo() {
|
|
7153
|
-
const db =
|
|
6921
|
+
const db = import_utils41.useAtlas.getDb();
|
|
7154
6922
|
if (!db) {
|
|
7155
6923
|
throw new Error("Unable to connect to server.");
|
|
7156
6924
|
}
|
|
7157
6925
|
const namespace_collection = "permissions";
|
|
7158
6926
|
const collection = db.collection(namespace_collection);
|
|
7159
|
-
const { getCache, setCache, delNamespace } = (0,
|
|
6927
|
+
const { getCache, setCache, delNamespace } = (0, import_utils41.useCache)(namespace_collection);
|
|
7160
6928
|
async function createIndexes() {
|
|
7161
6929
|
try {
|
|
7162
6930
|
await collection.createIndexes([
|
|
@@ -7178,7 +6946,7 @@ function usePermissionRepo() {
|
|
|
7178
6946
|
}
|
|
7179
6947
|
}
|
|
7180
6948
|
createIndexes().catch((error) => {
|
|
7181
|
-
|
|
6949
|
+
import_utils41.logger.log({ level: "error", message: `Index creation error: ${error}` });
|
|
7182
6950
|
});
|
|
7183
6951
|
async function add(value, session) {
|
|
7184
6952
|
try {
|
|
@@ -7187,16 +6955,16 @@ function usePermissionRepo() {
|
|
|
7187
6955
|
delCachedData();
|
|
7188
6956
|
return res.insertedId;
|
|
7189
6957
|
} catch (error) {
|
|
7190
|
-
|
|
6958
|
+
import_utils41.logger.log({
|
|
7191
6959
|
level: "error",
|
|
7192
6960
|
message: error.message
|
|
7193
6961
|
});
|
|
7194
|
-
if (error instanceof
|
|
6962
|
+
if (error instanceof import_utils41.AppError) {
|
|
7195
6963
|
throw error;
|
|
7196
6964
|
} else {
|
|
7197
6965
|
const isDuplicated = error.message.includes("duplicate");
|
|
7198
6966
|
if (isDuplicated) {
|
|
7199
|
-
throw new
|
|
6967
|
+
throw new import_utils41.BadRequestError("Permission already exists.");
|
|
7200
6968
|
}
|
|
7201
6969
|
throw new Error("Failed to create permission.");
|
|
7202
6970
|
}
|
|
@@ -7206,11 +6974,11 @@ function usePermissionRepo() {
|
|
|
7206
6974
|
try {
|
|
7207
6975
|
_id = new import_mongodb20.ObjectId(_id);
|
|
7208
6976
|
} catch (error2) {
|
|
7209
|
-
throw new
|
|
6977
|
+
throw new import_utils41.BadRequestError("Invalid ID.");
|
|
7210
6978
|
}
|
|
7211
6979
|
const { error } = schemaPermissionUpdate.validate(value);
|
|
7212
6980
|
if (error) {
|
|
7213
|
-
throw new
|
|
6981
|
+
throw new import_utils41.BadRequestError(`Invalid data: ${error.message}`);
|
|
7214
6982
|
}
|
|
7215
6983
|
try {
|
|
7216
6984
|
const res = await collection.updateOne(
|
|
@@ -7221,11 +6989,11 @@ function usePermissionRepo() {
|
|
|
7221
6989
|
delCachedData();
|
|
7222
6990
|
return res;
|
|
7223
6991
|
} catch (error2) {
|
|
7224
|
-
|
|
6992
|
+
import_utils41.logger.log({
|
|
7225
6993
|
level: "error",
|
|
7226
6994
|
message: error2.message
|
|
7227
6995
|
});
|
|
7228
|
-
if (error2 instanceof
|
|
6996
|
+
if (error2 instanceof import_utils41.AppError) {
|
|
7229
6997
|
throw error2;
|
|
7230
6998
|
} else {
|
|
7231
6999
|
throw new Error("Failed to update permission.");
|
|
@@ -7258,15 +7026,15 @@ function usePermissionRepo() {
|
|
|
7258
7026
|
query.app = app;
|
|
7259
7027
|
cacheParams.app = app;
|
|
7260
7028
|
}
|
|
7261
|
-
const cacheKey = (0,
|
|
7262
|
-
|
|
7029
|
+
const cacheKey = (0, import_utils41.makeCacheKey)(namespace_collection, cacheParams);
|
|
7030
|
+
import_utils41.logger.log({
|
|
7263
7031
|
level: "info",
|
|
7264
7032
|
message: `Cache key for getAll permissions: ${cacheKey}`
|
|
7265
7033
|
});
|
|
7266
7034
|
try {
|
|
7267
7035
|
const cached = await getCache(cacheKey);
|
|
7268
7036
|
if (cached) {
|
|
7269
|
-
|
|
7037
|
+
import_utils41.logger.log({
|
|
7270
7038
|
level: "info",
|
|
7271
7039
|
message: `Cache hit for getAll permissions: ${cacheKey}`
|
|
7272
7040
|
});
|
|
@@ -7279,21 +7047,21 @@ function usePermissionRepo() {
|
|
|
7279
7047
|
{ $limit: limit }
|
|
7280
7048
|
]).toArray();
|
|
7281
7049
|
const length = await collection.countDocuments(query);
|
|
7282
|
-
const data = (0,
|
|
7050
|
+
const data = (0, import_utils41.paginate)(items, page, limit, length);
|
|
7283
7051
|
setCache(cacheKey, data, 600).then(() => {
|
|
7284
|
-
|
|
7052
|
+
import_utils41.logger.log({
|
|
7285
7053
|
level: "info",
|
|
7286
7054
|
message: `Cache set for getAll permissions: ${cacheKey}`
|
|
7287
7055
|
});
|
|
7288
7056
|
}).catch((err) => {
|
|
7289
|
-
|
|
7057
|
+
import_utils41.logger.log({
|
|
7290
7058
|
level: "error",
|
|
7291
7059
|
message: `Failed to set cache for getAll permissions: ${err.message}`
|
|
7292
7060
|
});
|
|
7293
7061
|
});
|
|
7294
7062
|
return data;
|
|
7295
7063
|
} catch (error) {
|
|
7296
|
-
|
|
7064
|
+
import_utils41.logger.log({ level: "error", message: `${error}` });
|
|
7297
7065
|
throw error;
|
|
7298
7066
|
}
|
|
7299
7067
|
}
|
|
@@ -7301,13 +7069,13 @@ function usePermissionRepo() {
|
|
|
7301
7069
|
try {
|
|
7302
7070
|
_id = new import_mongodb20.ObjectId(_id);
|
|
7303
7071
|
} catch (error) {
|
|
7304
|
-
throw new
|
|
7072
|
+
throw new import_utils41.BadRequestError("Invalid ID.");
|
|
7305
7073
|
}
|
|
7306
|
-
const cacheKey = (0,
|
|
7074
|
+
const cacheKey = (0, import_utils41.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
7307
7075
|
try {
|
|
7308
7076
|
const cached = await getCache(cacheKey);
|
|
7309
7077
|
if (cached) {
|
|
7310
|
-
|
|
7078
|
+
import_utils41.logger.log({
|
|
7311
7079
|
level: "info",
|
|
7312
7080
|
message: `Cache hit for getById permission: ${cacheKey}`
|
|
7313
7081
|
});
|
|
@@ -7317,33 +7085,34 @@ function usePermissionRepo() {
|
|
|
7317
7085
|
_id
|
|
7318
7086
|
});
|
|
7319
7087
|
setCache(cacheKey, result, 300).then(() => {
|
|
7320
|
-
|
|
7088
|
+
import_utils41.logger.log({
|
|
7321
7089
|
level: "info",
|
|
7322
7090
|
message: `Cache set for permission by id: ${cacheKey}`
|
|
7323
7091
|
});
|
|
7324
7092
|
}).catch((err) => {
|
|
7325
|
-
|
|
7093
|
+
import_utils41.logger.log({
|
|
7326
7094
|
level: "error",
|
|
7327
7095
|
message: `Failed to set cache for permission by id: ${err.message}`
|
|
7328
7096
|
});
|
|
7329
7097
|
});
|
|
7330
7098
|
return result;
|
|
7331
7099
|
} catch (error) {
|
|
7332
|
-
if (error instanceof
|
|
7100
|
+
if (error instanceof import_utils41.AppError) {
|
|
7333
7101
|
throw error;
|
|
7334
7102
|
} else {
|
|
7335
|
-
throw new
|
|
7103
|
+
throw new import_utils41.InternalServerError("Failed to get permission.");
|
|
7336
7104
|
}
|
|
7337
7105
|
}
|
|
7338
7106
|
}
|
|
7339
|
-
async function getByKey(key, group) {
|
|
7340
|
-
const validation =
|
|
7341
|
-
key:
|
|
7342
|
-
group:
|
|
7107
|
+
async function getByKey(key, group, app) {
|
|
7108
|
+
const validation = import_joi22.default.object({
|
|
7109
|
+
key: import_joi22.default.string().required(),
|
|
7110
|
+
group: import_joi22.default.string().optional().allow("", null),
|
|
7111
|
+
app: import_joi22.default.string().optional().allow("", null)
|
|
7343
7112
|
});
|
|
7344
7113
|
const { error } = validation.validate({ key, group });
|
|
7345
7114
|
if (error) {
|
|
7346
|
-
throw new
|
|
7115
|
+
throw new import_utils41.BadRequestError(`Invalid data: ${error.message}`);
|
|
7347
7116
|
}
|
|
7348
7117
|
const query = {};
|
|
7349
7118
|
const cacheKeyOptions = {};
|
|
@@ -7353,11 +7122,15 @@ function usePermissionRepo() {
|
|
|
7353
7122
|
query.group = group;
|
|
7354
7123
|
cacheKeyOptions.group = group;
|
|
7355
7124
|
}
|
|
7356
|
-
|
|
7125
|
+
if (app) {
|
|
7126
|
+
query.app = app;
|
|
7127
|
+
cacheKeyOptions.app = app;
|
|
7128
|
+
}
|
|
7129
|
+
const cacheKey = (0, import_utils41.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
7357
7130
|
try {
|
|
7358
7131
|
const cached = await getCache(cacheKey);
|
|
7359
7132
|
if (cached) {
|
|
7360
|
-
|
|
7133
|
+
import_utils41.logger.log({
|
|
7361
7134
|
level: "info",
|
|
7362
7135
|
message: `Cache hit for getById permission: ${cacheKey}`
|
|
7363
7136
|
});
|
|
@@ -7365,34 +7138,34 @@ function usePermissionRepo() {
|
|
|
7365
7138
|
}
|
|
7366
7139
|
const result = await collection.findOne(query);
|
|
7367
7140
|
setCache(cacheKey, result, 300).then(() => {
|
|
7368
|
-
|
|
7141
|
+
import_utils41.logger.log({
|
|
7369
7142
|
level: "info",
|
|
7370
7143
|
message: `Cache set for permission by key: ${cacheKey}`
|
|
7371
7144
|
});
|
|
7372
7145
|
}).catch((err) => {
|
|
7373
|
-
|
|
7146
|
+
import_utils41.logger.log({
|
|
7374
7147
|
level: "error",
|
|
7375
7148
|
message: `Failed to set cache for permission by key: ${err.message}`
|
|
7376
7149
|
});
|
|
7377
7150
|
});
|
|
7378
7151
|
return result;
|
|
7379
7152
|
} catch (error2) {
|
|
7380
|
-
if (error2 instanceof
|
|
7153
|
+
if (error2 instanceof import_utils41.AppError) {
|
|
7381
7154
|
throw error2;
|
|
7382
7155
|
} else {
|
|
7383
|
-
throw new
|
|
7156
|
+
throw new import_utils41.InternalServerError("Failed to get permission.");
|
|
7384
7157
|
}
|
|
7385
7158
|
}
|
|
7386
7159
|
}
|
|
7387
7160
|
async function countByGroup(group) {
|
|
7388
|
-
const cacheKey = (0,
|
|
7161
|
+
const cacheKey = (0, import_utils41.makeCacheKey)(namespace_collection, {
|
|
7389
7162
|
group,
|
|
7390
7163
|
tag: "countByGroup"
|
|
7391
7164
|
});
|
|
7392
7165
|
try {
|
|
7393
7166
|
const cached = await getCache(cacheKey);
|
|
7394
7167
|
if (cached) {
|
|
7395
|
-
|
|
7168
|
+
import_utils41.logger.log({
|
|
7396
7169
|
level: "info",
|
|
7397
7170
|
message: `Cache hit for getById permission: ${cacheKey}`
|
|
7398
7171
|
});
|
|
@@ -7402,22 +7175,22 @@ function usePermissionRepo() {
|
|
|
7402
7175
|
group
|
|
7403
7176
|
});
|
|
7404
7177
|
setCache(cacheKey, result, 300).then(() => {
|
|
7405
|
-
|
|
7178
|
+
import_utils41.logger.log({
|
|
7406
7179
|
level: "info",
|
|
7407
7180
|
message: `Cache set for permission count by group: ${cacheKey}`
|
|
7408
7181
|
});
|
|
7409
7182
|
}).catch((err) => {
|
|
7410
|
-
|
|
7183
|
+
import_utils41.logger.log({
|
|
7411
7184
|
level: "error",
|
|
7412
7185
|
message: `Failed to set cache for permission by group: ${err.message}`
|
|
7413
7186
|
});
|
|
7414
7187
|
});
|
|
7415
7188
|
return result;
|
|
7416
7189
|
} catch (error) {
|
|
7417
|
-
if (error instanceof
|
|
7190
|
+
if (error instanceof import_utils41.AppError) {
|
|
7418
7191
|
throw error;
|
|
7419
7192
|
} else {
|
|
7420
|
-
throw new
|
|
7193
|
+
throw new import_utils41.InternalServerError("Failed to count permission by group.");
|
|
7421
7194
|
}
|
|
7422
7195
|
}
|
|
7423
7196
|
}
|
|
@@ -7425,7 +7198,7 @@ function usePermissionRepo() {
|
|
|
7425
7198
|
try {
|
|
7426
7199
|
_id = new import_mongodb20.ObjectId(_id);
|
|
7427
7200
|
} catch (error) {
|
|
7428
|
-
throw new
|
|
7201
|
+
throw new import_utils41.BadRequestError("Invalid ID.");
|
|
7429
7202
|
}
|
|
7430
7203
|
try {
|
|
7431
7204
|
const res = await collection.updateOne(
|
|
@@ -7435,25 +7208,25 @@ function usePermissionRepo() {
|
|
|
7435
7208
|
delCachedData();
|
|
7436
7209
|
return res;
|
|
7437
7210
|
} catch (error) {
|
|
7438
|
-
|
|
7211
|
+
import_utils41.logger.log({
|
|
7439
7212
|
level: "error",
|
|
7440
7213
|
message: error.message
|
|
7441
7214
|
});
|
|
7442
|
-
if (error instanceof
|
|
7215
|
+
if (error instanceof import_utils41.AppError) {
|
|
7443
7216
|
throw error;
|
|
7444
7217
|
} else {
|
|
7445
|
-
throw new
|
|
7218
|
+
throw new import_utils41.InternalServerError("Failed to delete permission.");
|
|
7446
7219
|
}
|
|
7447
7220
|
}
|
|
7448
7221
|
}
|
|
7449
7222
|
function delCachedData() {
|
|
7450
7223
|
delNamespace().then(() => {
|
|
7451
|
-
|
|
7224
|
+
import_utils41.logger.log({
|
|
7452
7225
|
level: "info",
|
|
7453
7226
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
7454
7227
|
});
|
|
7455
7228
|
}).catch((err) => {
|
|
7456
|
-
|
|
7229
|
+
import_utils41.logger.log({
|
|
7457
7230
|
level: "error",
|
|
7458
7231
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
7459
7232
|
});
|
|
@@ -7492,8 +7265,8 @@ function usePermissionService() {
|
|
|
7492
7265
|
}
|
|
7493
7266
|
|
|
7494
7267
|
// src/resources/permission/permission.controller.ts
|
|
7495
|
-
var
|
|
7496
|
-
var
|
|
7268
|
+
var import_utils42 = require("@goweekdays/utils");
|
|
7269
|
+
var import_joi23 = __toESM(require("joi"));
|
|
7497
7270
|
function usePermissionController() {
|
|
7498
7271
|
const {
|
|
7499
7272
|
getAll: _getAll,
|
|
@@ -7506,8 +7279,8 @@ function usePermissionController() {
|
|
|
7506
7279
|
const value = req.body;
|
|
7507
7280
|
const { error } = schemaPermission.validate(value);
|
|
7508
7281
|
if (error) {
|
|
7509
|
-
next(new
|
|
7510
|
-
|
|
7282
|
+
next(new import_utils42.BadRequestError(error.message));
|
|
7283
|
+
import_utils42.logger.info(`Controller: ${error.message}`);
|
|
7511
7284
|
return;
|
|
7512
7285
|
}
|
|
7513
7286
|
try {
|
|
@@ -7520,16 +7293,16 @@ function usePermissionController() {
|
|
|
7520
7293
|
}
|
|
7521
7294
|
async function getAll(req, res, next) {
|
|
7522
7295
|
const query = req.query;
|
|
7523
|
-
const validation =
|
|
7524
|
-
page:
|
|
7525
|
-
limit:
|
|
7526
|
-
search:
|
|
7527
|
-
app:
|
|
7528
|
-
status:
|
|
7296
|
+
const validation = import_joi23.default.object({
|
|
7297
|
+
page: import_joi23.default.number().min(1).optional().allow("", null),
|
|
7298
|
+
limit: import_joi23.default.number().min(1).optional().allow("", null),
|
|
7299
|
+
search: import_joi23.default.string().optional().allow("", null),
|
|
7300
|
+
app: import_joi23.default.string().optional().allow("", null),
|
|
7301
|
+
status: import_joi23.default.string().optional().allow("", null)
|
|
7529
7302
|
});
|
|
7530
7303
|
const { error } = validation.validate(query);
|
|
7531
7304
|
if (error) {
|
|
7532
|
-
next(new
|
|
7305
|
+
next(new import_utils42.BadRequestError(error.message));
|
|
7533
7306
|
return;
|
|
7534
7307
|
}
|
|
7535
7308
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -7563,12 +7336,12 @@ function usePermissionController() {
|
|
|
7563
7336
|
}
|
|
7564
7337
|
async function getById(req, res, next) {
|
|
7565
7338
|
const id = req.params.id;
|
|
7566
|
-
const validation =
|
|
7567
|
-
id:
|
|
7339
|
+
const validation = import_joi23.default.object({
|
|
7340
|
+
id: import_joi23.default.string().hex().required()
|
|
7568
7341
|
});
|
|
7569
7342
|
const { error } = validation.validate({ id });
|
|
7570
7343
|
if (error) {
|
|
7571
|
-
next(new
|
|
7344
|
+
next(new import_utils42.BadRequestError(error.message));
|
|
7572
7345
|
return;
|
|
7573
7346
|
}
|
|
7574
7347
|
try {
|
|
@@ -7584,12 +7357,12 @@ function usePermissionController() {
|
|
|
7584
7357
|
}
|
|
7585
7358
|
async function deleteById(req, res, next) {
|
|
7586
7359
|
const id = req.params.id;
|
|
7587
|
-
const validation =
|
|
7588
|
-
id:
|
|
7360
|
+
const validation = import_joi23.default.object({
|
|
7361
|
+
id: import_joi23.default.string().hex().required()
|
|
7589
7362
|
});
|
|
7590
7363
|
const { error } = validation.validate({ id });
|
|
7591
7364
|
if (error) {
|
|
7592
|
-
next(new
|
|
7365
|
+
next(new import_utils42.BadRequestError(error.message));
|
|
7593
7366
|
return;
|
|
7594
7367
|
}
|
|
7595
7368
|
try {
|
|
@@ -7602,15 +7375,15 @@ function usePermissionController() {
|
|
|
7602
7375
|
}
|
|
7603
7376
|
async function updateById(req, res, next) {
|
|
7604
7377
|
const id = req.params.id;
|
|
7605
|
-
const { error: errorId } =
|
|
7378
|
+
const { error: errorId } = import_joi23.default.string().hex().required().validate(id);
|
|
7606
7379
|
if (errorId) {
|
|
7607
|
-
next(new
|
|
7380
|
+
next(new import_utils42.BadRequestError(errorId.message));
|
|
7608
7381
|
return;
|
|
7609
7382
|
}
|
|
7610
7383
|
const payload = req.body;
|
|
7611
7384
|
const { error } = schemaPermissionUpdate.validate(payload);
|
|
7612
7385
|
if (error) {
|
|
7613
|
-
next(new
|
|
7386
|
+
next(new import_utils42.BadRequestError(error.message));
|
|
7614
7387
|
return;
|
|
7615
7388
|
}
|
|
7616
7389
|
try {
|
|
@@ -7631,23 +7404,23 @@ function usePermissionController() {
|
|
|
7631
7404
|
}
|
|
7632
7405
|
|
|
7633
7406
|
// src/resources/permission/permission.group.model.ts
|
|
7634
|
-
var
|
|
7635
|
-
var
|
|
7636
|
-
var schemaPermissionGroup =
|
|
7637
|
-
app:
|
|
7638
|
-
key:
|
|
7639
|
-
label:
|
|
7640
|
-
order:
|
|
7407
|
+
var import_utils43 = require("@goweekdays/utils");
|
|
7408
|
+
var import_joi24 = __toESM(require("joi"));
|
|
7409
|
+
var schemaPermissionGroup = import_joi24.default.object({
|
|
7410
|
+
app: import_joi24.default.string().required(),
|
|
7411
|
+
key: import_joi24.default.string().required(),
|
|
7412
|
+
label: import_joi24.default.string().required(),
|
|
7413
|
+
order: import_joi24.default.number().integer().optional().allow("", null)
|
|
7641
7414
|
});
|
|
7642
|
-
var schemaPermissionGroupUpdate =
|
|
7643
|
-
key:
|
|
7644
|
-
label:
|
|
7645
|
-
order:
|
|
7415
|
+
var schemaPermissionGroupUpdate = import_joi24.default.object({
|
|
7416
|
+
key: import_joi24.default.string().optional().allow("", null),
|
|
7417
|
+
label: import_joi24.default.string().optional().allow("", null),
|
|
7418
|
+
order: import_joi24.default.number().integer().optional().allow("", null)
|
|
7646
7419
|
});
|
|
7647
7420
|
function modelPermissionGroup(value) {
|
|
7648
7421
|
const { error } = schemaPermissionGroup.validate(value);
|
|
7649
7422
|
if (error) {
|
|
7650
|
-
throw new
|
|
7423
|
+
throw new import_utils43.BadRequestError(error.message);
|
|
7651
7424
|
}
|
|
7652
7425
|
return {
|
|
7653
7426
|
_id: value._id,
|
|
@@ -7663,18 +7436,18 @@ function modelPermissionGroup(value) {
|
|
|
7663
7436
|
}
|
|
7664
7437
|
|
|
7665
7438
|
// src/resources/permission/permission.group.repository.ts
|
|
7666
|
-
var
|
|
7439
|
+
var import_utils44 = require("@goweekdays/utils");
|
|
7667
7440
|
var import_mongodb21 = require("mongodb");
|
|
7668
|
-
var
|
|
7669
|
-
var
|
|
7441
|
+
var import_joi25 = __toESM(require("joi"));
|
|
7442
|
+
var init2 = false;
|
|
7670
7443
|
function usePermissionGroupRepo() {
|
|
7671
|
-
const db =
|
|
7444
|
+
const db = import_utils44.useAtlas.getDb();
|
|
7672
7445
|
if (!db) {
|
|
7673
7446
|
throw new Error("Unable to connect to server.");
|
|
7674
7447
|
}
|
|
7675
7448
|
const namespace_collection = "permission.groups";
|
|
7676
7449
|
const collection = db.collection(namespace_collection);
|
|
7677
|
-
const { getCache, setCache, delNamespace } = (0,
|
|
7450
|
+
const { getCache, setCache, delNamespace } = (0, import_utils44.useCache)(namespace_collection);
|
|
7678
7451
|
async function createIndexes() {
|
|
7679
7452
|
try {
|
|
7680
7453
|
await collection.createIndexes([
|
|
@@ -7695,33 +7468,32 @@ function usePermissionGroupRepo() {
|
|
|
7695
7468
|
throw new Error("Failed to create index on permission groups.");
|
|
7696
7469
|
}
|
|
7697
7470
|
}
|
|
7698
|
-
if (!
|
|
7471
|
+
if (!init2) {
|
|
7699
7472
|
createIndexes().catch((error) => {
|
|
7700
|
-
|
|
7473
|
+
import_utils44.logger.log({
|
|
7701
7474
|
level: "error",
|
|
7702
7475
|
message: `Index creation error: ${error}`
|
|
7703
7476
|
});
|
|
7704
7477
|
});
|
|
7705
|
-
|
|
7478
|
+
init2 = true;
|
|
7706
7479
|
}
|
|
7707
7480
|
async function add(value, session) {
|
|
7708
7481
|
try {
|
|
7709
7482
|
value = modelPermissionGroup(value);
|
|
7710
|
-
console.log(value);
|
|
7711
7483
|
const res = await collection.insertOne(value, { session });
|
|
7712
7484
|
delCachedData();
|
|
7713
7485
|
return res.insertedId;
|
|
7714
7486
|
} catch (error) {
|
|
7715
|
-
|
|
7487
|
+
import_utils44.logger.log({
|
|
7716
7488
|
level: "error",
|
|
7717
7489
|
message: error.message
|
|
7718
7490
|
});
|
|
7719
|
-
if (error instanceof
|
|
7491
|
+
if (error instanceof import_utils44.AppError) {
|
|
7720
7492
|
throw error;
|
|
7721
7493
|
} else {
|
|
7722
7494
|
const isDuplicated = error.message.includes("duplicate");
|
|
7723
7495
|
if (isDuplicated) {
|
|
7724
|
-
throw new
|
|
7496
|
+
throw new import_utils44.BadRequestError("Permission group already exists.");
|
|
7725
7497
|
}
|
|
7726
7498
|
throw new Error("Failed to create permission group.");
|
|
7727
7499
|
}
|
|
@@ -7731,11 +7503,11 @@ function usePermissionGroupRepo() {
|
|
|
7731
7503
|
try {
|
|
7732
7504
|
_id = new import_mongodb21.ObjectId(_id);
|
|
7733
7505
|
} catch (error2) {
|
|
7734
|
-
throw new
|
|
7506
|
+
throw new import_utils44.BadRequestError("Invalid ID.");
|
|
7735
7507
|
}
|
|
7736
7508
|
const { error } = schemaPermissionGroupUpdate.validate(value);
|
|
7737
7509
|
if (error) {
|
|
7738
|
-
throw new
|
|
7510
|
+
throw new import_utils44.BadRequestError(`Invalid data: ${error.message}`);
|
|
7739
7511
|
}
|
|
7740
7512
|
try {
|
|
7741
7513
|
const res = await collection.updateOne(
|
|
@@ -7746,11 +7518,11 @@ function usePermissionGroupRepo() {
|
|
|
7746
7518
|
delCachedData();
|
|
7747
7519
|
return res;
|
|
7748
7520
|
} catch (error2) {
|
|
7749
|
-
|
|
7521
|
+
import_utils44.logger.log({
|
|
7750
7522
|
level: "error",
|
|
7751
7523
|
message: error2.message
|
|
7752
7524
|
});
|
|
7753
|
-
if (error2 instanceof
|
|
7525
|
+
if (error2 instanceof import_utils44.AppError) {
|
|
7754
7526
|
throw error2;
|
|
7755
7527
|
} else {
|
|
7756
7528
|
throw new Error("Failed to update permission group.");
|
|
@@ -7783,15 +7555,15 @@ function usePermissionGroupRepo() {
|
|
|
7783
7555
|
query.app = app;
|
|
7784
7556
|
cacheParams.app = app;
|
|
7785
7557
|
}
|
|
7786
|
-
const cacheKey = (0,
|
|
7787
|
-
|
|
7558
|
+
const cacheKey = (0, import_utils44.makeCacheKey)(namespace_collection, cacheParams);
|
|
7559
|
+
import_utils44.logger.log({
|
|
7788
7560
|
level: "info",
|
|
7789
7561
|
message: `Cache key for getAll permission groups: ${cacheKey}`
|
|
7790
7562
|
});
|
|
7791
7563
|
try {
|
|
7792
7564
|
const cached = await getCache(cacheKey);
|
|
7793
7565
|
if (cached) {
|
|
7794
|
-
|
|
7566
|
+
import_utils44.logger.log({
|
|
7795
7567
|
level: "info",
|
|
7796
7568
|
message: `Cache hit for getAll permission groups: ${cacheKey}`
|
|
7797
7569
|
});
|
|
@@ -7804,21 +7576,21 @@ function usePermissionGroupRepo() {
|
|
|
7804
7576
|
{ $limit: limit }
|
|
7805
7577
|
]).toArray();
|
|
7806
7578
|
const length = await collection.countDocuments(query);
|
|
7807
|
-
const data = (0,
|
|
7579
|
+
const data = (0, import_utils44.paginate)(items, page, limit, length);
|
|
7808
7580
|
setCache(cacheKey, data, 600).then(() => {
|
|
7809
|
-
|
|
7581
|
+
import_utils44.logger.log({
|
|
7810
7582
|
level: "info",
|
|
7811
7583
|
message: `Cache set for getAll permission groups: ${cacheKey}`
|
|
7812
7584
|
});
|
|
7813
7585
|
}).catch((err) => {
|
|
7814
|
-
|
|
7586
|
+
import_utils44.logger.log({
|
|
7815
7587
|
level: "error",
|
|
7816
7588
|
message: `Failed to set cache for getAll permission groups: ${err.message}`
|
|
7817
7589
|
});
|
|
7818
7590
|
});
|
|
7819
7591
|
return data;
|
|
7820
7592
|
} catch (error) {
|
|
7821
|
-
|
|
7593
|
+
import_utils44.logger.log({ level: "error", message: `${error}` });
|
|
7822
7594
|
throw error;
|
|
7823
7595
|
}
|
|
7824
7596
|
}
|
|
@@ -7826,13 +7598,13 @@ function usePermissionGroupRepo() {
|
|
|
7826
7598
|
try {
|
|
7827
7599
|
_id = new import_mongodb21.ObjectId(_id);
|
|
7828
7600
|
} catch (error) {
|
|
7829
|
-
throw new
|
|
7601
|
+
throw new import_utils44.BadRequestError("Invalid ID.");
|
|
7830
7602
|
}
|
|
7831
|
-
const cacheKey = (0,
|
|
7603
|
+
const cacheKey = (0, import_utils44.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
7832
7604
|
try {
|
|
7833
7605
|
const cached = await getCache(cacheKey);
|
|
7834
7606
|
if (cached) {
|
|
7835
|
-
|
|
7607
|
+
import_utils44.logger.log({
|
|
7836
7608
|
level: "info",
|
|
7837
7609
|
message: `Cache hit for getById permission group: ${cacheKey}`
|
|
7838
7610
|
});
|
|
@@ -7842,33 +7614,33 @@ function usePermissionGroupRepo() {
|
|
|
7842
7614
|
_id
|
|
7843
7615
|
});
|
|
7844
7616
|
setCache(cacheKey, result, 300).then(() => {
|
|
7845
|
-
|
|
7617
|
+
import_utils44.logger.log({
|
|
7846
7618
|
level: "info",
|
|
7847
7619
|
message: `Cache set for permission group by id: ${cacheKey}`
|
|
7848
7620
|
});
|
|
7849
7621
|
}).catch((err) => {
|
|
7850
|
-
|
|
7622
|
+
import_utils44.logger.log({
|
|
7851
7623
|
level: "error",
|
|
7852
7624
|
message: `Failed to set cache for permission group by id: ${err.message}`
|
|
7853
7625
|
});
|
|
7854
7626
|
});
|
|
7855
7627
|
return result;
|
|
7856
7628
|
} catch (error) {
|
|
7857
|
-
if (error instanceof
|
|
7629
|
+
if (error instanceof import_utils44.AppError) {
|
|
7858
7630
|
throw error;
|
|
7859
7631
|
} else {
|
|
7860
|
-
throw new
|
|
7632
|
+
throw new import_utils44.InternalServerError("Failed to get permission group.");
|
|
7861
7633
|
}
|
|
7862
7634
|
}
|
|
7863
7635
|
}
|
|
7864
7636
|
async function getByKey(key, app) {
|
|
7865
|
-
const validation =
|
|
7866
|
-
key:
|
|
7867
|
-
app:
|
|
7637
|
+
const validation = import_joi25.default.object({
|
|
7638
|
+
key: import_joi25.default.string().required(),
|
|
7639
|
+
app: import_joi25.default.string().optional().allow(null, "")
|
|
7868
7640
|
});
|
|
7869
7641
|
const { error } = validation.validate({ key, app });
|
|
7870
7642
|
if (error) {
|
|
7871
|
-
throw new
|
|
7643
|
+
throw new import_utils44.BadRequestError("Invalid key.");
|
|
7872
7644
|
}
|
|
7873
7645
|
const query = { key };
|
|
7874
7646
|
const cacheKeyOptions = { key, tag: "byKey" };
|
|
@@ -7876,11 +7648,11 @@ function usePermissionGroupRepo() {
|
|
|
7876
7648
|
query.app = app;
|
|
7877
7649
|
cacheKeyOptions.app = app;
|
|
7878
7650
|
}
|
|
7879
|
-
const cacheKey = (0,
|
|
7651
|
+
const cacheKey = (0, import_utils44.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
7880
7652
|
try {
|
|
7881
7653
|
const cached = await getCache(cacheKey);
|
|
7882
7654
|
if (cached) {
|
|
7883
|
-
|
|
7655
|
+
import_utils44.logger.log({
|
|
7884
7656
|
level: "info",
|
|
7885
7657
|
message: `Cache hit for getById permission group: ${cacheKey}`
|
|
7886
7658
|
});
|
|
@@ -7888,22 +7660,22 @@ function usePermissionGroupRepo() {
|
|
|
7888
7660
|
}
|
|
7889
7661
|
const result = await collection.findOne(query);
|
|
7890
7662
|
setCache(cacheKey, result, 300).then(() => {
|
|
7891
|
-
|
|
7663
|
+
import_utils44.logger.log({
|
|
7892
7664
|
level: "info",
|
|
7893
7665
|
message: `Cache set for permission group by key: ${cacheKey}`
|
|
7894
7666
|
});
|
|
7895
7667
|
}).catch((err) => {
|
|
7896
|
-
|
|
7668
|
+
import_utils44.logger.log({
|
|
7897
7669
|
level: "error",
|
|
7898
7670
|
message: `Failed to set cache for permission group by key: ${err.message}`
|
|
7899
7671
|
});
|
|
7900
7672
|
});
|
|
7901
7673
|
return result;
|
|
7902
7674
|
} catch (error2) {
|
|
7903
|
-
if (error2 instanceof
|
|
7675
|
+
if (error2 instanceof import_utils44.AppError) {
|
|
7904
7676
|
throw error2;
|
|
7905
7677
|
} else {
|
|
7906
|
-
throw new
|
|
7678
|
+
throw new import_utils44.InternalServerError("Failed to get permission group.");
|
|
7907
7679
|
}
|
|
7908
7680
|
}
|
|
7909
7681
|
}
|
|
@@ -7911,7 +7683,7 @@ function usePermissionGroupRepo() {
|
|
|
7911
7683
|
try {
|
|
7912
7684
|
_id = new import_mongodb21.ObjectId(_id);
|
|
7913
7685
|
} catch (error) {
|
|
7914
|
-
throw new
|
|
7686
|
+
throw new import_utils44.BadRequestError("Invalid ID.");
|
|
7915
7687
|
}
|
|
7916
7688
|
try {
|
|
7917
7689
|
const res = await collection.updateOne(
|
|
@@ -7921,25 +7693,25 @@ function usePermissionGroupRepo() {
|
|
|
7921
7693
|
delCachedData();
|
|
7922
7694
|
return res;
|
|
7923
7695
|
} catch (error) {
|
|
7924
|
-
|
|
7696
|
+
import_utils44.logger.log({
|
|
7925
7697
|
level: "error",
|
|
7926
7698
|
message: error.message
|
|
7927
7699
|
});
|
|
7928
|
-
if (error instanceof
|
|
7700
|
+
if (error instanceof import_utils44.AppError) {
|
|
7929
7701
|
throw error;
|
|
7930
7702
|
} else {
|
|
7931
|
-
throw new
|
|
7703
|
+
throw new import_utils44.InternalServerError("Failed to delete permission group.");
|
|
7932
7704
|
}
|
|
7933
7705
|
}
|
|
7934
7706
|
}
|
|
7935
7707
|
function delCachedData() {
|
|
7936
7708
|
delNamespace().then(() => {
|
|
7937
|
-
|
|
7709
|
+
import_utils44.logger.log({
|
|
7938
7710
|
level: "info",
|
|
7939
7711
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
7940
7712
|
});
|
|
7941
7713
|
}).catch((err) => {
|
|
7942
|
-
|
|
7714
|
+
import_utils44.logger.log({
|
|
7943
7715
|
level: "error",
|
|
7944
7716
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
7945
7717
|
});
|
|
@@ -7957,8 +7729,7 @@ function usePermissionGroupRepo() {
|
|
|
7957
7729
|
}
|
|
7958
7730
|
|
|
7959
7731
|
// src/resources/permission/permission.group.service.ts
|
|
7960
|
-
var
|
|
7961
|
-
var init4 = false;
|
|
7732
|
+
var import_utils45 = require("@goweekdays/utils");
|
|
7962
7733
|
function usePermissionGroupService() {
|
|
7963
7734
|
const {
|
|
7964
7735
|
updateById: _updateById,
|
|
@@ -7974,7 +7745,7 @@ function usePermissionGroupService() {
|
|
|
7974
7745
|
add: addPermission
|
|
7975
7746
|
} = usePermissionRepo();
|
|
7976
7747
|
async function addDefaultModule() {
|
|
7977
|
-
const session =
|
|
7748
|
+
const session = import_utils45.useAtlas.getClient()?.startSession();
|
|
7978
7749
|
if (!session) {
|
|
7979
7750
|
throw new Error("Failed to start database session.");
|
|
7980
7751
|
}
|
|
@@ -8051,14 +7822,14 @@ function usePermissionGroupService() {
|
|
|
8051
7822
|
];
|
|
8052
7823
|
for (const app of apps.items) {
|
|
8053
7824
|
for (const module2 of modules) {
|
|
8054
|
-
const existingGroup = await _getByKey(module2.key);
|
|
7825
|
+
const existingGroup = await _getByKey(module2.key, app.code);
|
|
8055
7826
|
if (!existingGroup) {
|
|
8056
7827
|
await _add({
|
|
8057
7828
|
app: app.code,
|
|
8058
7829
|
key: module2.key,
|
|
8059
7830
|
label: module2.label
|
|
8060
7831
|
});
|
|
8061
|
-
|
|
7832
|
+
import_utils45.logger.log({
|
|
8062
7833
|
level: "info",
|
|
8063
7834
|
message: `Default permission group added: ${app.code} - ${module2.key}`
|
|
8064
7835
|
});
|
|
@@ -8066,7 +7837,8 @@ function usePermissionGroupService() {
|
|
|
8066
7837
|
for (const permission of module2.permissions) {
|
|
8067
7838
|
const existingPermission = await getPermissionByKey(
|
|
8068
7839
|
permission.key,
|
|
8069
|
-
module2.key
|
|
7840
|
+
module2.key,
|
|
7841
|
+
app.code
|
|
8070
7842
|
);
|
|
8071
7843
|
if (!existingPermission) {
|
|
8072
7844
|
await addPermission({
|
|
@@ -8237,7 +8009,7 @@ function usePermissionGroupService() {
|
|
|
8237
8009
|
key: module2.key,
|
|
8238
8010
|
label: module2.label
|
|
8239
8011
|
});
|
|
8240
|
-
|
|
8012
|
+
import_utils45.logger.log({
|
|
8241
8013
|
level: "info",
|
|
8242
8014
|
message: `Default permission group added: ${app.code} - ${module2.key}`
|
|
8243
8015
|
});
|
|
@@ -8261,7 +8033,7 @@ function usePermissionGroupService() {
|
|
|
8261
8033
|
}
|
|
8262
8034
|
await session.commitTransaction();
|
|
8263
8035
|
}
|
|
8264
|
-
|
|
8036
|
+
import_utils45.logger.log({
|
|
8265
8037
|
level: "info",
|
|
8266
8038
|
message: "Default permission groups added successfully."
|
|
8267
8039
|
});
|
|
@@ -8274,15 +8046,6 @@ function usePermissionGroupService() {
|
|
|
8274
8046
|
await session.endSession();
|
|
8275
8047
|
}
|
|
8276
8048
|
}
|
|
8277
|
-
if (!init4) {
|
|
8278
|
-
addDefaultModule().catch((error) => {
|
|
8279
|
-
import_utils47.logger.log({
|
|
8280
|
-
level: "error",
|
|
8281
|
-
message: `Error in addDefaultModule: ${error}`
|
|
8282
|
-
});
|
|
8283
|
-
});
|
|
8284
|
-
init4 = true;
|
|
8285
|
-
}
|
|
8286
8049
|
async function deleteById(id) {
|
|
8287
8050
|
const permission = await _getById(id);
|
|
8288
8051
|
if (!permission) {
|
|
@@ -8290,7 +8053,7 @@ function usePermissionGroupService() {
|
|
|
8290
8053
|
}
|
|
8291
8054
|
const associatedPermissionsCount = await countByGroup(permission.key);
|
|
8292
8055
|
if (associatedPermissionsCount > 0) {
|
|
8293
|
-
throw new
|
|
8056
|
+
throw new import_utils45.BadRequestError(
|
|
8294
8057
|
"Cannot delete Permission Group with associated Permissions."
|
|
8295
8058
|
);
|
|
8296
8059
|
}
|
|
@@ -8298,21 +8061,22 @@ function usePermissionGroupService() {
|
|
|
8298
8061
|
await _deleteById(id);
|
|
8299
8062
|
return "Permission deleted successfully.";
|
|
8300
8063
|
} catch (error) {
|
|
8301
|
-
if (error instanceof
|
|
8064
|
+
if (error instanceof import_utils45.AppError) {
|
|
8302
8065
|
throw error;
|
|
8303
8066
|
} else {
|
|
8304
|
-
throw new
|
|
8067
|
+
throw new import_utils45.InternalServerError("Failed to delete Permission Group.");
|
|
8305
8068
|
}
|
|
8306
8069
|
}
|
|
8307
8070
|
}
|
|
8308
8071
|
return {
|
|
8072
|
+
addDefaultModule,
|
|
8309
8073
|
deleteById
|
|
8310
8074
|
};
|
|
8311
8075
|
}
|
|
8312
8076
|
|
|
8313
8077
|
// src/resources/permission/permission.group.controller.ts
|
|
8314
|
-
var
|
|
8315
|
-
var
|
|
8078
|
+
var import_utils46 = require("@goweekdays/utils");
|
|
8079
|
+
var import_joi26 = __toESM(require("joi"));
|
|
8316
8080
|
function usePermissionGroupController() {
|
|
8317
8081
|
const {
|
|
8318
8082
|
getAll: _getAll,
|
|
@@ -8325,8 +8089,8 @@ function usePermissionGroupController() {
|
|
|
8325
8089
|
const value = req.body;
|
|
8326
8090
|
const { error } = schemaPermissionGroup.validate(value);
|
|
8327
8091
|
if (error) {
|
|
8328
|
-
next(new
|
|
8329
|
-
|
|
8092
|
+
next(new import_utils46.BadRequestError(error.message));
|
|
8093
|
+
import_utils46.logger.info(`Controller: ${error.message}`);
|
|
8330
8094
|
return;
|
|
8331
8095
|
}
|
|
8332
8096
|
try {
|
|
@@ -8339,16 +8103,16 @@ function usePermissionGroupController() {
|
|
|
8339
8103
|
}
|
|
8340
8104
|
async function getAll(req, res, next) {
|
|
8341
8105
|
const query = req.query;
|
|
8342
|
-
const validation =
|
|
8343
|
-
page:
|
|
8344
|
-
limit:
|
|
8345
|
-
search:
|
|
8346
|
-
app:
|
|
8347
|
-
status:
|
|
8106
|
+
const validation = import_joi26.default.object({
|
|
8107
|
+
page: import_joi26.default.number().min(1).optional().allow("", null),
|
|
8108
|
+
limit: import_joi26.default.number().min(1).optional().allow("", null),
|
|
8109
|
+
search: import_joi26.default.string().optional().allow("", null),
|
|
8110
|
+
app: import_joi26.default.string().optional().allow("", null),
|
|
8111
|
+
status: import_joi26.default.string().optional().allow("", null)
|
|
8348
8112
|
});
|
|
8349
8113
|
const { error } = validation.validate(query);
|
|
8350
8114
|
if (error) {
|
|
8351
|
-
next(new
|
|
8115
|
+
next(new import_utils46.BadRequestError(error.message));
|
|
8352
8116
|
return;
|
|
8353
8117
|
}
|
|
8354
8118
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -8382,12 +8146,12 @@ function usePermissionGroupController() {
|
|
|
8382
8146
|
}
|
|
8383
8147
|
async function getById(req, res, next) {
|
|
8384
8148
|
const id = req.params.id;
|
|
8385
|
-
const validation =
|
|
8386
|
-
id:
|
|
8149
|
+
const validation = import_joi26.default.object({
|
|
8150
|
+
id: import_joi26.default.string().hex().required()
|
|
8387
8151
|
});
|
|
8388
8152
|
const { error } = validation.validate({ id });
|
|
8389
8153
|
if (error) {
|
|
8390
|
-
next(new
|
|
8154
|
+
next(new import_utils46.BadRequestError(error.message));
|
|
8391
8155
|
return;
|
|
8392
8156
|
}
|
|
8393
8157
|
try {
|
|
@@ -8403,12 +8167,12 @@ function usePermissionGroupController() {
|
|
|
8403
8167
|
}
|
|
8404
8168
|
async function deleteById(req, res, next) {
|
|
8405
8169
|
const id = req.params.id;
|
|
8406
|
-
const validation =
|
|
8407
|
-
id:
|
|
8170
|
+
const validation = import_joi26.default.object({
|
|
8171
|
+
id: import_joi26.default.string().hex().required()
|
|
8408
8172
|
});
|
|
8409
8173
|
const { error } = validation.validate({ id });
|
|
8410
8174
|
if (error) {
|
|
8411
|
-
next(new
|
|
8175
|
+
next(new import_utils46.BadRequestError(error.message));
|
|
8412
8176
|
return;
|
|
8413
8177
|
}
|
|
8414
8178
|
try {
|
|
@@ -8421,15 +8185,15 @@ function usePermissionGroupController() {
|
|
|
8421
8185
|
}
|
|
8422
8186
|
async function updateById(req, res, next) {
|
|
8423
8187
|
const id = req.params.id;
|
|
8424
|
-
const { error: errorId } =
|
|
8188
|
+
const { error: errorId } = import_joi26.default.string().hex().required().validate(id);
|
|
8425
8189
|
if (errorId) {
|
|
8426
|
-
next(new
|
|
8190
|
+
next(new import_utils46.BadRequestError(errorId.message));
|
|
8427
8191
|
return;
|
|
8428
8192
|
}
|
|
8429
8193
|
const payload = req.body;
|
|
8430
8194
|
const { error } = schemaPermissionGroupUpdate.validate(payload);
|
|
8431
8195
|
if (error) {
|
|
8432
|
-
next(new
|
|
8196
|
+
next(new import_utils46.BadRequestError(error.message));
|
|
8433
8197
|
return;
|
|
8434
8198
|
}
|
|
8435
8199
|
try {
|
|
@@ -8448,6 +8212,248 @@ function usePermissionGroupController() {
|
|
|
8448
8212
|
updateById
|
|
8449
8213
|
};
|
|
8450
8214
|
}
|
|
8215
|
+
|
|
8216
|
+
// src/resources/app/app.service.ts
|
|
8217
|
+
var init3 = false;
|
|
8218
|
+
function useAppService() {
|
|
8219
|
+
const {
|
|
8220
|
+
updateById: _updateById,
|
|
8221
|
+
getById: _getById,
|
|
8222
|
+
deleteById: _deleteById,
|
|
8223
|
+
getByCode: _getByCode,
|
|
8224
|
+
add: _add
|
|
8225
|
+
} = useAppRepo();
|
|
8226
|
+
const { addDefaultModule } = usePermissionGroupService();
|
|
8227
|
+
async function addDefaultApps() {
|
|
8228
|
+
const apps = [
|
|
8229
|
+
{
|
|
8230
|
+
code: "admin",
|
|
8231
|
+
name: "Admin",
|
|
8232
|
+
description: "Administrative application.",
|
|
8233
|
+
type: "default"
|
|
8234
|
+
},
|
|
8235
|
+
{
|
|
8236
|
+
code: "marketplace",
|
|
8237
|
+
name: "Marketplace",
|
|
8238
|
+
description: "Marketplace for product listings."
|
|
8239
|
+
},
|
|
8240
|
+
{
|
|
8241
|
+
code: "service",
|
|
8242
|
+
name: "Services",
|
|
8243
|
+
description: "Service offerings and management."
|
|
8244
|
+
},
|
|
8245
|
+
{
|
|
8246
|
+
code: "stay",
|
|
8247
|
+
name: "Stay",
|
|
8248
|
+
description: "Accommodation and lodging services."
|
|
8249
|
+
},
|
|
8250
|
+
{ code: "eat", name: "Eat", description: "Food and dining services." },
|
|
8251
|
+
{
|
|
8252
|
+
code: "experience",
|
|
8253
|
+
name: "Experience",
|
|
8254
|
+
description: "Experiential touring, travel, activities and events."
|
|
8255
|
+
},
|
|
8256
|
+
{
|
|
8257
|
+
code: "ride",
|
|
8258
|
+
name: "Ride",
|
|
8259
|
+
description: "Transportation and ride services."
|
|
8260
|
+
}
|
|
8261
|
+
];
|
|
8262
|
+
const session = import_utils47.useAtlas.getClient()?.startSession();
|
|
8263
|
+
if (!session) {
|
|
8264
|
+
throw new Error("Failed to start database session.");
|
|
8265
|
+
}
|
|
8266
|
+
try {
|
|
8267
|
+
session?.startTransaction();
|
|
8268
|
+
for (const app of apps) {
|
|
8269
|
+
const existingApp = await _getByCode(app.code);
|
|
8270
|
+
if (!existingApp) {
|
|
8271
|
+
await _add(app, session);
|
|
8272
|
+
}
|
|
8273
|
+
}
|
|
8274
|
+
await session.commitTransaction();
|
|
8275
|
+
import_utils47.logger.log({
|
|
8276
|
+
level: "info",
|
|
8277
|
+
message: "Default apps added successfully."
|
|
8278
|
+
});
|
|
8279
|
+
return;
|
|
8280
|
+
} catch (error) {
|
|
8281
|
+
await session.abortTransaction();
|
|
8282
|
+
import_utils47.logger.log({
|
|
8283
|
+
level: "error",
|
|
8284
|
+
message: `Failed to add default apps: ${error}`
|
|
8285
|
+
});
|
|
8286
|
+
throw error;
|
|
8287
|
+
} finally {
|
|
8288
|
+
await session.endSession();
|
|
8289
|
+
}
|
|
8290
|
+
}
|
|
8291
|
+
if (!init3) {
|
|
8292
|
+
addDefaultApps().catch((error) => {
|
|
8293
|
+
import_utils47.logger.log({
|
|
8294
|
+
level: "error",
|
|
8295
|
+
message: `Error in addDefaultApps: ${error}`
|
|
8296
|
+
});
|
|
8297
|
+
}).then(() => {
|
|
8298
|
+
addDefaultModule().catch((error) => {
|
|
8299
|
+
import_utils47.logger.log({
|
|
8300
|
+
level: "error",
|
|
8301
|
+
message: `Error in addDefaultModule: ${error}`
|
|
8302
|
+
});
|
|
8303
|
+
});
|
|
8304
|
+
});
|
|
8305
|
+
init3 = true;
|
|
8306
|
+
}
|
|
8307
|
+
async function deleteById(id) {
|
|
8308
|
+
try {
|
|
8309
|
+
await _deleteById(id);
|
|
8310
|
+
return "App deleted successfully.";
|
|
8311
|
+
} catch (error) {
|
|
8312
|
+
throw error;
|
|
8313
|
+
}
|
|
8314
|
+
}
|
|
8315
|
+
return {
|
|
8316
|
+
deleteById
|
|
8317
|
+
};
|
|
8318
|
+
}
|
|
8319
|
+
|
|
8320
|
+
// src/resources/app/app.controller.ts
|
|
8321
|
+
var import_utils48 = require("@goweekdays/utils");
|
|
8322
|
+
var import_joi27 = __toESM(require("joi"));
|
|
8323
|
+
function useAppController() {
|
|
8324
|
+
const {
|
|
8325
|
+
getAll: _getAll,
|
|
8326
|
+
getById: _getById,
|
|
8327
|
+
add: _add,
|
|
8328
|
+
updateById: _updateById
|
|
8329
|
+
} = useAppRepo();
|
|
8330
|
+
const { deleteById: _deleteById } = useAppService();
|
|
8331
|
+
async function add(req, res, next) {
|
|
8332
|
+
const value = req.body;
|
|
8333
|
+
const { error } = schemaApp.validate(value);
|
|
8334
|
+
if (error) {
|
|
8335
|
+
next(new import_utils48.BadRequestError(error.message));
|
|
8336
|
+
return;
|
|
8337
|
+
}
|
|
8338
|
+
try {
|
|
8339
|
+
const result = await _add(value);
|
|
8340
|
+
res.json(result);
|
|
8341
|
+
return;
|
|
8342
|
+
} catch (error2) {
|
|
8343
|
+
next(error2);
|
|
8344
|
+
}
|
|
8345
|
+
}
|
|
8346
|
+
async function updateById(req, res, next) {
|
|
8347
|
+
const id = req.params.id ?? "";
|
|
8348
|
+
const { error: errorId } = import_joi27.default.string().hex().required().validate(id);
|
|
8349
|
+
if (errorId) {
|
|
8350
|
+
next(new import_utils48.BadRequestError(errorId.message));
|
|
8351
|
+
return;
|
|
8352
|
+
}
|
|
8353
|
+
const value = req.body;
|
|
8354
|
+
const { error } = schemaAppUpdate.validate(value);
|
|
8355
|
+
if (error) {
|
|
8356
|
+
next(new import_utils48.BadRequestError(error.message));
|
|
8357
|
+
return;
|
|
8358
|
+
}
|
|
8359
|
+
try {
|
|
8360
|
+
const result = await _updateById(req.params.id, value);
|
|
8361
|
+
res.json(result);
|
|
8362
|
+
return;
|
|
8363
|
+
} catch (error2) {
|
|
8364
|
+
next(error2);
|
|
8365
|
+
}
|
|
8366
|
+
}
|
|
8367
|
+
async function getAll(req, res, next) {
|
|
8368
|
+
const query = req.query;
|
|
8369
|
+
const validation = import_joi27.default.object({
|
|
8370
|
+
page: import_joi27.default.number().min(1).optional().allow("", null),
|
|
8371
|
+
limit: import_joi27.default.number().min(1).optional().allow("", null),
|
|
8372
|
+
search: import_joi27.default.string().optional().allow("", null),
|
|
8373
|
+
status: import_joi27.default.string().optional().allow("", null),
|
|
8374
|
+
type: import_joi27.default.string().optional().allow("", null)
|
|
8375
|
+
});
|
|
8376
|
+
const { error } = validation.validate(query);
|
|
8377
|
+
if (error) {
|
|
8378
|
+
next(new import_utils48.BadRequestError(error.message));
|
|
8379
|
+
return;
|
|
8380
|
+
}
|
|
8381
|
+
const page = parseInt(req.query.page) ?? 1;
|
|
8382
|
+
let limit = parseInt(req.query.limit) ?? 20;
|
|
8383
|
+
limit = isNaN(limit) ? 20 : limit;
|
|
8384
|
+
const sort = req.query.sort ? String(req.query.sort).split(",") : "";
|
|
8385
|
+
const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
|
|
8386
|
+
const sortObj = {};
|
|
8387
|
+
if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
|
|
8388
|
+
sort.forEach((field, index) => {
|
|
8389
|
+
sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
|
|
8390
|
+
});
|
|
8391
|
+
}
|
|
8392
|
+
const status = req.query.status ?? "active";
|
|
8393
|
+
const search = req.query.search ?? "";
|
|
8394
|
+
let type = req.query.type ? req.query.type.split(",") : "standard";
|
|
8395
|
+
try {
|
|
8396
|
+
const buildings = await _getAll({
|
|
8397
|
+
page,
|
|
8398
|
+
limit,
|
|
8399
|
+
sort: sortObj,
|
|
8400
|
+
status,
|
|
8401
|
+
search,
|
|
8402
|
+
type
|
|
8403
|
+
});
|
|
8404
|
+
res.json(buildings);
|
|
8405
|
+
return;
|
|
8406
|
+
} catch (error2) {
|
|
8407
|
+
next(error2);
|
|
8408
|
+
}
|
|
8409
|
+
}
|
|
8410
|
+
async function getById(req, res, next) {
|
|
8411
|
+
const id = req.params.id;
|
|
8412
|
+
const validation = import_joi27.default.object({
|
|
8413
|
+
id: import_joi27.default.string().hex().required()
|
|
8414
|
+
});
|
|
8415
|
+
const { error } = validation.validate({ id });
|
|
8416
|
+
if (error) {
|
|
8417
|
+
next(new import_utils48.BadRequestError(error.message));
|
|
8418
|
+
return;
|
|
8419
|
+
}
|
|
8420
|
+
try {
|
|
8421
|
+
const data = await _getById(id);
|
|
8422
|
+
res.json({
|
|
8423
|
+
message: "Successfully retrieved app.",
|
|
8424
|
+
data
|
|
8425
|
+
});
|
|
8426
|
+
return;
|
|
8427
|
+
} catch (error2) {
|
|
8428
|
+
next(error2);
|
|
8429
|
+
}
|
|
8430
|
+
}
|
|
8431
|
+
async function deleteById(req, res, next) {
|
|
8432
|
+
const id = req.params.id;
|
|
8433
|
+
const validation = import_joi27.default.object({
|
|
8434
|
+
id: import_joi27.default.string().hex().required()
|
|
8435
|
+
});
|
|
8436
|
+
const { error } = validation.validate({ id });
|
|
8437
|
+
if (error) {
|
|
8438
|
+
next(new import_utils48.BadRequestError(error.message));
|
|
8439
|
+
return;
|
|
8440
|
+
}
|
|
8441
|
+
try {
|
|
8442
|
+
const message = await _deleteById(id);
|
|
8443
|
+
res.json(message);
|
|
8444
|
+
return;
|
|
8445
|
+
} catch (error2) {
|
|
8446
|
+
next(error2);
|
|
8447
|
+
}
|
|
8448
|
+
}
|
|
8449
|
+
return {
|
|
8450
|
+
add,
|
|
8451
|
+
updateById,
|
|
8452
|
+
getAll,
|
|
8453
|
+
getById,
|
|
8454
|
+
deleteById
|
|
8455
|
+
};
|
|
8456
|
+
}
|
|
8451
8457
|
// Annotate the CommonJS export names for ESM import in node:
|
|
8452
8458
|
0 && (module.exports = {
|
|
8453
8459
|
ACCESS_TOKEN_EXPIRY,
|