@7365admin1/core 2.82.0 → 2.83.0
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 +7 -0
- package/dist/index.js +179 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +179 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2487,11 +2487,15 @@ declare function useCustomerSiteRepo(): {
|
|
|
2487
2487
|
org: string | ObjectId;
|
|
2488
2488
|
}) => Promise<TCustomerSite[]>;
|
|
2489
2489
|
getBySiteAsServiceProvider: (site: string | ObjectId) => Promise<{} | undefined>;
|
|
2490
|
+
getById: (id: string | ObjectId) => Promise<mongodb.WithId<bson.Document>>;
|
|
2491
|
+
updateCustomerSiteById: (id: string | ObjectId, payload: Partial<TCustomerSite>, session?: ClientSession) => Promise<mongodb.WithId<bson.Document>>;
|
|
2492
|
+
deleteById: (id: string | ObjectId, session?: ClientSession) => Promise<mongodb.WithId<bson.Document>>;
|
|
2490
2493
|
};
|
|
2491
2494
|
|
|
2492
2495
|
declare function useCustomerSiteService(): {
|
|
2493
2496
|
add: (value: TCustomerSite) => Promise<string>;
|
|
2494
2497
|
addViaInvite: (invite: string) => Promise<string>;
|
|
2498
|
+
updateCusSiteById: (customerSiteId: string, payload: Partial<TCustomerSite>) => Promise<mongodb.WithId<bson.Document>>;
|
|
2495
2499
|
};
|
|
2496
2500
|
|
|
2497
2501
|
declare function useCustomerSiteController(): {
|
|
@@ -2499,6 +2503,9 @@ declare function useCustomerSiteController(): {
|
|
|
2499
2503
|
getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2500
2504
|
addViaInvite: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2501
2505
|
getBySiteAsServiceProvider: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2506
|
+
getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2507
|
+
updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2508
|
+
deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2502
2509
|
};
|
|
2503
2510
|
|
|
2504
2511
|
type TAttendance = {
|
package/dist/index.js
CHANGED
|
@@ -30148,12 +30148,91 @@ function useCustomerSiteRepo() {
|
|
|
30148
30148
|
} catch (error) {
|
|
30149
30149
|
}
|
|
30150
30150
|
}
|
|
30151
|
+
async function getById(id) {
|
|
30152
|
+
try {
|
|
30153
|
+
id = new import_mongodb54.ObjectId(id);
|
|
30154
|
+
} catch {
|
|
30155
|
+
throw new import_node_server_utils94.BadRequestError("Invalid ID.");
|
|
30156
|
+
}
|
|
30157
|
+
const data = await collection.findOne({
|
|
30158
|
+
_id: id
|
|
30159
|
+
});
|
|
30160
|
+
if (!data) {
|
|
30161
|
+
throw new import_node_server_utils94.BadRequestError("Customer site not found.");
|
|
30162
|
+
}
|
|
30163
|
+
return data;
|
|
30164
|
+
}
|
|
30165
|
+
async function updateCustomerSiteById(id, payload, session) {
|
|
30166
|
+
try {
|
|
30167
|
+
id = new import_mongodb54.ObjectId(id);
|
|
30168
|
+
} catch {
|
|
30169
|
+
throw new import_node_server_utils94.BadRequestError("Invalid ID.");
|
|
30170
|
+
}
|
|
30171
|
+
delete payload._id;
|
|
30172
|
+
const result = await collection.findOneAndUpdate(
|
|
30173
|
+
{ _id: id, status: "active" },
|
|
30174
|
+
{
|
|
30175
|
+
$set: {
|
|
30176
|
+
...payload,
|
|
30177
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
30178
|
+
}
|
|
30179
|
+
},
|
|
30180
|
+
{
|
|
30181
|
+
returnDocument: "after",
|
|
30182
|
+
session
|
|
30183
|
+
}
|
|
30184
|
+
);
|
|
30185
|
+
if (!result) {
|
|
30186
|
+
throw new import_node_server_utils94.BadRequestError("Customer site not found.");
|
|
30187
|
+
}
|
|
30188
|
+
delNamespace().then(() => {
|
|
30189
|
+
import_node_server_utils94.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
30190
|
+
}).catch((err) => {
|
|
30191
|
+
import_node_server_utils94.logger.error(`Failed to clear cache for namespace: ${namespace_collection}`, err);
|
|
30192
|
+
});
|
|
30193
|
+
return result;
|
|
30194
|
+
}
|
|
30195
|
+
async function deleteById(id, session) {
|
|
30196
|
+
try {
|
|
30197
|
+
id = new import_mongodb54.ObjectId(id);
|
|
30198
|
+
} catch {
|
|
30199
|
+
throw new import_node_server_utils94.BadRequestError("Invalid ID.");
|
|
30200
|
+
}
|
|
30201
|
+
const result = await collection.findOneAndUpdate(
|
|
30202
|
+
{
|
|
30203
|
+
_id: id,
|
|
30204
|
+
status: { $ne: "deleted" }
|
|
30205
|
+
},
|
|
30206
|
+
{
|
|
30207
|
+
$set: {
|
|
30208
|
+
status: "deleted",
|
|
30209
|
+
deletedAt: /* @__PURE__ */ new Date()
|
|
30210
|
+
}
|
|
30211
|
+
},
|
|
30212
|
+
{
|
|
30213
|
+
returnDocument: "after",
|
|
30214
|
+
session
|
|
30215
|
+
}
|
|
30216
|
+
);
|
|
30217
|
+
if (!result) {
|
|
30218
|
+
throw new import_node_server_utils94.BadRequestError("Customer site not found.");
|
|
30219
|
+
}
|
|
30220
|
+
delNamespace().then(() => {
|
|
30221
|
+
import_node_server_utils94.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
30222
|
+
}).catch((err) => {
|
|
30223
|
+
import_node_server_utils94.logger.error(`Failed to clear cache for namespace: ${namespace_collection}`, err);
|
|
30224
|
+
});
|
|
30225
|
+
return result;
|
|
30226
|
+
}
|
|
30151
30227
|
return {
|
|
30152
30228
|
createIndexes,
|
|
30153
30229
|
add,
|
|
30154
30230
|
getAll,
|
|
30155
30231
|
getByName,
|
|
30156
|
-
getBySiteAsServiceProvider
|
|
30232
|
+
getBySiteAsServiceProvider,
|
|
30233
|
+
getById,
|
|
30234
|
+
updateCustomerSiteById,
|
|
30235
|
+
deleteById
|
|
30157
30236
|
};
|
|
30158
30237
|
}
|
|
30159
30238
|
|
|
@@ -30161,12 +30240,13 @@ function useCustomerSiteRepo() {
|
|
|
30161
30240
|
var import_node_server_utils95 = require("@7365admin1/node-server-utils");
|
|
30162
30241
|
var import_fast_levenshtein = __toESM(require("fast-levenshtein"));
|
|
30163
30242
|
function useCustomerSiteService() {
|
|
30164
|
-
const { add: _add } = useCustomerSiteRepo();
|
|
30243
|
+
const { add: _add, updateCustomerSiteById, getById: _getById } = useCustomerSiteRepo();
|
|
30165
30244
|
const {
|
|
30166
30245
|
getByName: getSiteByName,
|
|
30167
30246
|
getByExactName: getSiteByExactName,
|
|
30168
30247
|
createSite,
|
|
30169
|
-
getSiteById
|
|
30248
|
+
getSiteById,
|
|
30249
|
+
updateSiteById
|
|
30170
30250
|
} = useSiteRepo();
|
|
30171
30251
|
const {
|
|
30172
30252
|
getById: _getByOrgId,
|
|
@@ -30297,9 +30377,47 @@ function useCustomerSiteService() {
|
|
|
30297
30377
|
session?.endSession();
|
|
30298
30378
|
}
|
|
30299
30379
|
}
|
|
30380
|
+
async function updateCusSiteById(customerSiteId, payload) {
|
|
30381
|
+
const session = import_node_server_utils95.useAtlas.getClient()?.startSession();
|
|
30382
|
+
session?.startTransaction();
|
|
30383
|
+
try {
|
|
30384
|
+
const customerSite = await _getById(customerSiteId);
|
|
30385
|
+
if (!customerSite) {
|
|
30386
|
+
throw new import_node_server_utils95.NotFoundError("Customer site not found.");
|
|
30387
|
+
}
|
|
30388
|
+
const siteId = customerSite.site;
|
|
30389
|
+
await updateSiteById(
|
|
30390
|
+
siteId,
|
|
30391
|
+
{
|
|
30392
|
+
...payload.name !== void 0 && { name: payload.name },
|
|
30393
|
+
...payload.address !== void 0 && { address: payload.address },
|
|
30394
|
+
...payload.category !== void 0 && { category: payload.category }
|
|
30395
|
+
},
|
|
30396
|
+
session
|
|
30397
|
+
);
|
|
30398
|
+
const safePayload = {
|
|
30399
|
+
...payload.name !== void 0 && { name: payload.name },
|
|
30400
|
+
...payload.address !== void 0 && { address: payload.address },
|
|
30401
|
+
...payload.category !== void 0 && { category: payload.category }
|
|
30402
|
+
};
|
|
30403
|
+
const result = await updateCustomerSiteById(
|
|
30404
|
+
customerSiteId,
|
|
30405
|
+
safePayload,
|
|
30406
|
+
session
|
|
30407
|
+
);
|
|
30408
|
+
await session?.commitTransaction();
|
|
30409
|
+
return result;
|
|
30410
|
+
} catch (error) {
|
|
30411
|
+
await session?.abortTransaction();
|
|
30412
|
+
throw error;
|
|
30413
|
+
} finally {
|
|
30414
|
+
await session?.endSession();
|
|
30415
|
+
}
|
|
30416
|
+
}
|
|
30300
30417
|
return {
|
|
30301
30418
|
add,
|
|
30302
|
-
addViaInvite
|
|
30419
|
+
addViaInvite,
|
|
30420
|
+
updateCusSiteById
|
|
30303
30421
|
};
|
|
30304
30422
|
}
|
|
30305
30423
|
|
|
@@ -30309,9 +30427,11 @@ var import_node_server_utils96 = require("@7365admin1/node-server-utils");
|
|
|
30309
30427
|
function useCustomerSiteController() {
|
|
30310
30428
|
const {
|
|
30311
30429
|
getAll: _getAll,
|
|
30312
|
-
getBySiteAsServiceProvider: _getBySiteAsServiceProvider
|
|
30430
|
+
getBySiteAsServiceProvider: _getBySiteAsServiceProvider,
|
|
30431
|
+
getById: _getById,
|
|
30432
|
+
deleteById: _deleteById
|
|
30313
30433
|
} = useCustomerSiteRepo();
|
|
30314
|
-
const { add: _add, addViaInvite: _addViaInvite } = useCustomerSiteService();
|
|
30434
|
+
const { add: _add, addViaInvite: _addViaInvite, updateCusSiteById: _updateCusSiteById } = useCustomerSiteService();
|
|
30315
30435
|
async function add(req, res, next) {
|
|
30316
30436
|
const { error, value } = schemaCustomerSite.validate(req.body);
|
|
30317
30437
|
if (error) {
|
|
@@ -30428,11 +30548,63 @@ function useCustomerSiteController() {
|
|
|
30428
30548
|
return;
|
|
30429
30549
|
}
|
|
30430
30550
|
}
|
|
30551
|
+
async function getById(req, res, next) {
|
|
30552
|
+
const validation = import_joi52.default.object({
|
|
30553
|
+
id: import_joi52.default.string().hex().required()
|
|
30554
|
+
});
|
|
30555
|
+
const id = req.params.id;
|
|
30556
|
+
const { error } = validation.validate({ id });
|
|
30557
|
+
if (error) {
|
|
30558
|
+
next(new import_node_server_utils96.BadRequestError(error.message));
|
|
30559
|
+
return;
|
|
30560
|
+
}
|
|
30561
|
+
try {
|
|
30562
|
+
const data = await _getById(id);
|
|
30563
|
+
res.json(data);
|
|
30564
|
+
return;
|
|
30565
|
+
} catch (error2) {
|
|
30566
|
+
next(error2);
|
|
30567
|
+
return;
|
|
30568
|
+
}
|
|
30569
|
+
}
|
|
30570
|
+
async function updateById(req, res, next) {
|
|
30571
|
+
const validation = import_joi52.default.object({
|
|
30572
|
+
id: import_joi52.default.string().hex().required()
|
|
30573
|
+
});
|
|
30574
|
+
const id = req.params.id;
|
|
30575
|
+
const { error } = validation.validate({ id });
|
|
30576
|
+
if (error) {
|
|
30577
|
+
next(new import_node_server_utils96.BadRequestError(error.message));
|
|
30578
|
+
return;
|
|
30579
|
+
}
|
|
30580
|
+
try {
|
|
30581
|
+
const data = await _updateCusSiteById(id, req.body);
|
|
30582
|
+
res.json(data);
|
|
30583
|
+
return;
|
|
30584
|
+
} catch (error2) {
|
|
30585
|
+
next(error2);
|
|
30586
|
+
return;
|
|
30587
|
+
}
|
|
30588
|
+
}
|
|
30589
|
+
async function deleteById(req, res, next) {
|
|
30590
|
+
const id = req.params.id;
|
|
30591
|
+
try {
|
|
30592
|
+
const data = await _deleteById(id);
|
|
30593
|
+
res.json(data);
|
|
30594
|
+
return;
|
|
30595
|
+
} catch (error) {
|
|
30596
|
+
next(error);
|
|
30597
|
+
return;
|
|
30598
|
+
}
|
|
30599
|
+
}
|
|
30431
30600
|
return {
|
|
30432
30601
|
add,
|
|
30433
30602
|
getAll,
|
|
30434
30603
|
addViaInvite,
|
|
30435
|
-
getBySiteAsServiceProvider
|
|
30604
|
+
getBySiteAsServiceProvider,
|
|
30605
|
+
getById,
|
|
30606
|
+
updateById,
|
|
30607
|
+
deleteById
|
|
30436
30608
|
};
|
|
30437
30609
|
}
|
|
30438
30610
|
|