@goweekdays/core 1.1.8 → 1.2.1
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 +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +89 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1260,6 +1260,7 @@ declare function useMemberRepo(): {
|
|
|
1260
1260
|
}[]>;
|
|
1261
1261
|
countByOrg: (org: string | ObjectId) => Promise<number>;
|
|
1262
1262
|
countByUser: (user: string | ObjectId) => Promise<number>;
|
|
1263
|
+
getByUserType: (user: string | ObjectId, type: string, org?: string | ObjectId) => Promise<TMember | null>;
|
|
1263
1264
|
};
|
|
1264
1265
|
|
|
1265
1266
|
declare function useMemberController(): {
|
|
@@ -1267,6 +1268,7 @@ declare function useMemberController(): {
|
|
|
1267
1268
|
getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1268
1269
|
getOrgsByMembership: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1269
1270
|
updateStatusByUserId: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1271
|
+
getByUserType: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1270
1272
|
};
|
|
1271
1273
|
|
|
1272
1274
|
declare const schema: Joi.ObjectSchema<any>;
|
package/dist/index.js
CHANGED
|
@@ -12586,6 +12586,59 @@ function useMemberRepo() {
|
|
|
12586
12586
|
);
|
|
12587
12587
|
}
|
|
12588
12588
|
}
|
|
12589
|
+
async function getByUserType(user, type, org) {
|
|
12590
|
+
const query = {
|
|
12591
|
+
type,
|
|
12592
|
+
status: "active"
|
|
12593
|
+
};
|
|
12594
|
+
const cacheKeyOptions = {
|
|
12595
|
+
type
|
|
12596
|
+
};
|
|
12597
|
+
if (org) {
|
|
12598
|
+
try {
|
|
12599
|
+
org = new import_mongodb6.ObjectId(org);
|
|
12600
|
+
cacheKeyOptions.org = String(org);
|
|
12601
|
+
query.org = org;
|
|
12602
|
+
} catch (error) {
|
|
12603
|
+
throw new import_utils5.BadRequestError("Invalid ID.");
|
|
12604
|
+
}
|
|
12605
|
+
}
|
|
12606
|
+
try {
|
|
12607
|
+
user = new import_mongodb6.ObjectId(user);
|
|
12608
|
+
cacheKeyOptions.user = String(user);
|
|
12609
|
+
query.user = user;
|
|
12610
|
+
} catch (error) {
|
|
12611
|
+
throw new import_utils5.BadRequestError("Invalid ID.");
|
|
12612
|
+
}
|
|
12613
|
+
try {
|
|
12614
|
+
const cacheKey = (0, import_utils5.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
12615
|
+
const cached = await getCache(cacheKey);
|
|
12616
|
+
if (cached) {
|
|
12617
|
+
import_utils5.logger.log({
|
|
12618
|
+
level: "info",
|
|
12619
|
+
message: `Cache hit for getByUserId member: ${cacheKey}`
|
|
12620
|
+
});
|
|
12621
|
+
return cached;
|
|
12622
|
+
}
|
|
12623
|
+
const data = await collection.findOne(query);
|
|
12624
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
12625
|
+
import_utils5.logger.log({
|
|
12626
|
+
level: "info",
|
|
12627
|
+
message: `Cache set for member by user ID: ${cacheKey}`
|
|
12628
|
+
});
|
|
12629
|
+
}).catch((err) => {
|
|
12630
|
+
import_utils5.logger.log({
|
|
12631
|
+
level: "error",
|
|
12632
|
+
message: `Failed to set cache for member by user ID: ${err.message}`
|
|
12633
|
+
});
|
|
12634
|
+
});
|
|
12635
|
+
return data;
|
|
12636
|
+
} catch (error) {
|
|
12637
|
+
throw new import_utils5.InternalServerError(
|
|
12638
|
+
"Internal server error, failed to retrieve member."
|
|
12639
|
+
);
|
|
12640
|
+
}
|
|
12641
|
+
}
|
|
12589
12642
|
async function updateName(value, session) {
|
|
12590
12643
|
try {
|
|
12591
12644
|
value.user = new import_mongodb6.ObjectId(value.user);
|
|
@@ -12771,7 +12824,11 @@ function useMemberRepo() {
|
|
|
12771
12824
|
} catch (error) {
|
|
12772
12825
|
throw new import_utils5.BadRequestError("Invalid user ID.");
|
|
12773
12826
|
}
|
|
12774
|
-
const query = {
|
|
12827
|
+
const query = {
|
|
12828
|
+
user,
|
|
12829
|
+
status: { $ne: "deleted" },
|
|
12830
|
+
org: { $nin: [null, ""] }
|
|
12831
|
+
};
|
|
12775
12832
|
const cacheKeyOptions = {
|
|
12776
12833
|
user: String(user),
|
|
12777
12834
|
org: JSON.stringify(query.org),
|
|
@@ -12949,7 +13006,8 @@ function useMemberRepo() {
|
|
|
12949
13006
|
getByUserId,
|
|
12950
13007
|
getOrgsByMembership,
|
|
12951
13008
|
countByOrg,
|
|
12952
|
-
countByUser
|
|
13009
|
+
countByUser,
|
|
13010
|
+
getByUserType
|
|
12953
13011
|
};
|
|
12954
13012
|
}
|
|
12955
13013
|
|
|
@@ -24471,7 +24529,8 @@ function useMemberController() {
|
|
|
24471
24529
|
getByUserId: _getByUserId,
|
|
24472
24530
|
getAll: _getAll,
|
|
24473
24531
|
getOrgsByMembership: _getOrgsByMembership,
|
|
24474
|
-
updateStatusByUserId: _updateStatusByUserId
|
|
24532
|
+
updateStatusByUserId: _updateStatusByUserId,
|
|
24533
|
+
getByUserType: _getByUserType
|
|
24475
24534
|
} = useMemberRepo();
|
|
24476
24535
|
async function getByUserId(req, res, next) {
|
|
24477
24536
|
const userId = req.params.id;
|
|
@@ -24494,6 +24553,31 @@ function useMemberController() {
|
|
|
24494
24553
|
next(error2);
|
|
24495
24554
|
}
|
|
24496
24555
|
}
|
|
24556
|
+
async function getByUserType(req, res, next) {
|
|
24557
|
+
const validation = import_joi21.default.object({
|
|
24558
|
+
org: import_joi21.default.string().hex().optional().allow("", null),
|
|
24559
|
+
user: import_joi21.default.string().hex().required(),
|
|
24560
|
+
type: import_joi21.default.string().required()
|
|
24561
|
+
});
|
|
24562
|
+
const { error } = validation.validate({ ...req.params, ...req.query });
|
|
24563
|
+
if (error) {
|
|
24564
|
+
next(new import_utils72.BadRequestError(error.message));
|
|
24565
|
+
return;
|
|
24566
|
+
}
|
|
24567
|
+
const orgId = req.query.org;
|
|
24568
|
+
const userId = req.params.user;
|
|
24569
|
+
const type = req.params.type;
|
|
24570
|
+
try {
|
|
24571
|
+
const member = await _getByUserType(userId, type, orgId);
|
|
24572
|
+
if (!member) {
|
|
24573
|
+
res.status(404).json({ message: "Member not found." });
|
|
24574
|
+
return;
|
|
24575
|
+
}
|
|
24576
|
+
res.json(member);
|
|
24577
|
+
} catch (error2) {
|
|
24578
|
+
next(error2);
|
|
24579
|
+
}
|
|
24580
|
+
}
|
|
24497
24581
|
async function getAll(req, res, next) {
|
|
24498
24582
|
const limit = Number(req.query.limit) ?? 10;
|
|
24499
24583
|
const search = req.query.search ?? "";
|
|
@@ -24596,7 +24680,8 @@ function useMemberController() {
|
|
|
24596
24680
|
getByUserId,
|
|
24597
24681
|
getAll,
|
|
24598
24682
|
getOrgsByMembership,
|
|
24599
|
-
updateStatusByUserId
|
|
24683
|
+
updateStatusByUserId,
|
|
24684
|
+
getByUserType
|
|
24600
24685
|
};
|
|
24601
24686
|
}
|
|
24602
24687
|
|