@7365admin1/core 3.48.1-staging.190 → 3.48.1-staging.191
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/.changeset/manpower-designation-site-scope.md +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/harness.mjs +15 -0
- package/test/e2e/manpower-designation-scope.e2e.test.mjs +407 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@7365admin1/core": patch
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Scope the manpower designation routes to the estate, and stamp who filed the plan
|
|
6
|
+
from the session. `/api/manpower-designations` carried `requireAuth` and nothing
|
|
7
|
+
else on all three routes: any signed-in account could file a manning plan into
|
|
8
|
+
another estate, read any estate's guard-strength plan, or rewrite one by id alone.
|
|
9
|
+
`createdBy` and `createdByName` were taken from the request body, so the plan could
|
|
10
|
+
be attributed to anybody. Reach is now checked on the site named in the request and
|
|
11
|
+
on the stored row for the update, and the two identity fields come from the session.
|
package/dist/index.d.ts
CHANGED
|
@@ -8807,6 +8807,7 @@ declare class MManpowerDesignations implements Partial<TManpowerDesignations> {
|
|
|
8807
8807
|
declare function useManpowerDesignationRepo(): {
|
|
8808
8808
|
createManpowerDesignations: (value: TManpowerDesignations) => Promise<mongodb.InsertOneResult<bson.Document>>;
|
|
8809
8809
|
getManpowerDesignationsBySiteId: (_id: string | ObjectId, serviceProviderId?: string | ObjectId) => Promise<mongodb.WithId<bson.Document> | null>;
|
|
8810
|
+
getManpowerDesignationsById: (_id: string | ObjectId) => Promise<mongodb.WithId<bson.Document> | null>;
|
|
8810
8811
|
updateManpowerDesignations: (_id: string | ObjectId, value: TManpowerDesignationsUpdate) => Promise<number>;
|
|
8811
8812
|
createIndexes: () => Promise<string>;
|
|
8812
8813
|
};
|
package/dist/index.js
CHANGED
|
@@ -76993,6 +76993,14 @@ function useManpowerDesignationRepo() {
|
|
|
76993
76993
|
throw error;
|
|
76994
76994
|
}
|
|
76995
76995
|
}
|
|
76996
|
+
async function getManpowerDesignationsById(_id) {
|
|
76997
|
+
try {
|
|
76998
|
+
_id = new import_mongodb151.ObjectId(_id);
|
|
76999
|
+
} catch (error) {
|
|
77000
|
+
return null;
|
|
77001
|
+
}
|
|
77002
|
+
return await collection.findOne({ _id });
|
|
77003
|
+
}
|
|
76996
77004
|
async function updateManpowerDesignations(_id, value) {
|
|
76997
77005
|
try {
|
|
76998
77006
|
_id = new import_mongodb151.ObjectId(_id);
|
|
@@ -77016,6 +77024,7 @@ function useManpowerDesignationRepo() {
|
|
|
77016
77024
|
return {
|
|
77017
77025
|
createManpowerDesignations,
|
|
77018
77026
|
getManpowerDesignationsBySiteId,
|
|
77027
|
+
getManpowerDesignationsById,
|
|
77019
77028
|
updateManpowerDesignations,
|
|
77020
77029
|
createIndexes
|
|
77021
77030
|
};
|
|
@@ -77028,8 +77037,17 @@ function useManpowerDesignationCtrl() {
|
|
|
77028
77037
|
const {
|
|
77029
77038
|
createManpowerDesignations: _createManpowerDesignations,
|
|
77030
77039
|
getManpowerDesignationsBySiteId: _getManpowerDesignationsBySiteId,
|
|
77040
|
+
getManpowerDesignationsById: _getManpowerDesignationsById,
|
|
77031
77041
|
updateManpowerDesignations: _updateManpowerDesignations
|
|
77032
77042
|
} = useManpowerDesignationRepo();
|
|
77043
|
+
async function requireDesignationReach(req, _id) {
|
|
77044
|
+
const row = await _getManpowerDesignationsById(_id);
|
|
77045
|
+
const { canReach } = await siteReachOf(req);
|
|
77046
|
+
if (!row || !await canReach({ site: row.siteId })) {
|
|
77047
|
+
throw new import_node_server_utils241.NotFoundError("Manpower designations not found.");
|
|
77048
|
+
}
|
|
77049
|
+
return row;
|
|
77050
|
+
}
|
|
77033
77051
|
async function createManpowerDesignations(req, res, next) {
|
|
77034
77052
|
try {
|
|
77035
77053
|
const payload = { ...req.body };
|
|
@@ -77038,6 +77056,12 @@ function useManpowerDesignationCtrl() {
|
|
|
77038
77056
|
next(new import_node_server_utils241.BadRequestError(error.message));
|
|
77039
77057
|
return;
|
|
77040
77058
|
}
|
|
77059
|
+
const { actor, canReach } = await siteReachOf(req);
|
|
77060
|
+
if (!await canReach({ site: payload.siteId })) {
|
|
77061
|
+
throw new import_node_server_utils241.NotFoundError("Site not found.");
|
|
77062
|
+
}
|
|
77063
|
+
payload.createdBy = actor.id;
|
|
77064
|
+
payload.createdByName = actor.name;
|
|
77041
77065
|
const result = await _createManpowerDesignations(payload);
|
|
77042
77066
|
return res.json(result);
|
|
77043
77067
|
} catch (error) {
|
|
@@ -77058,6 +77082,7 @@ function useManpowerDesignationCtrl() {
|
|
|
77058
77082
|
next(new import_node_server_utils241.BadRequestError(error.message));
|
|
77059
77083
|
return;
|
|
77060
77084
|
}
|
|
77085
|
+
await requireSiteReach(req, id);
|
|
77061
77086
|
const result = await _getManpowerDesignationsBySiteId(
|
|
77062
77087
|
id,
|
|
77063
77088
|
serviceProviderId
|
|
@@ -77082,6 +77107,7 @@ function useManpowerDesignationCtrl() {
|
|
|
77082
77107
|
next(new import_node_server_utils241.BadRequestError(error.message));
|
|
77083
77108
|
return;
|
|
77084
77109
|
}
|
|
77110
|
+
await requireDesignationReach(req, _id);
|
|
77085
77111
|
const result = await _updateManpowerDesignations(_id, payload);
|
|
77086
77112
|
return res.json(result);
|
|
77087
77113
|
} catch (error) {
|