@chevre/domain 22.10.0-alpha.13 → 22.10.0-alpha.14
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.
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../../lib/index';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
|
+
|
|
9
|
+
const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
|
|
10
|
+
|
|
11
|
+
const roleNames = [
|
|
12
|
+
chevre.factory.iam.RoleName.InventoryManager,
|
|
13
|
+
chevre.factory.iam.RoleName.SellersOwner,
|
|
14
|
+
chevre.factory.iam.RoleName.SellersInventoryManager
|
|
15
|
+
];
|
|
16
|
+
for (const roleName of roleNames) {
|
|
17
|
+
const result = await roleRepo.addPermissionIfNotExists({
|
|
18
|
+
roleName: { $eq: roleName },
|
|
19
|
+
permission: 'eventOffers.*'
|
|
20
|
+
});
|
|
21
|
+
console.log(result, roleName);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
main()
|
|
26
|
+
.then()
|
|
27
|
+
.catch(console.error);
|
|
@@ -39,7 +39,10 @@ function countRedisKeyByProject(params: {
|
|
|
39
39
|
$eq: params.project.id
|
|
40
40
|
// $in: useMongoAsStockHolderProjects
|
|
41
41
|
},
|
|
42
|
-
startDate: {
|
|
42
|
+
// startDate: {
|
|
43
|
+
// $gte: params.now
|
|
44
|
+
// },
|
|
45
|
+
endDate: {
|
|
43
46
|
$gte: params.now
|
|
44
47
|
},
|
|
45
48
|
typeOf: { $eq: chevre.factory.eventType.ScreeningEvent }
|
|
@@ -16,4 +16,12 @@ export declare class RoleRepo {
|
|
|
16
16
|
}): Promise<{
|
|
17
17
|
_id: string;
|
|
18
18
|
}[]>;
|
|
19
|
+
addPermissionIfNotExists(params: {
|
|
20
|
+
roleName: {
|
|
21
|
+
$eq: factory.iam.RoleName;
|
|
22
|
+
};
|
|
23
|
+
permission: string;
|
|
24
|
+
}): Promise<(import("mongoose").FlattenMaps<IRole> & {
|
|
25
|
+
_id: import("mongoose").Types.ObjectId;
|
|
26
|
+
}) | null>;
|
|
19
27
|
}
|
package/lib/chevre/repo/role.js
CHANGED
|
@@ -99,5 +99,25 @@ class RoleRepo {
|
|
|
99
99
|
.exec();
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
+
addPermissionIfNotExists(params) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
return this.roleModel.findOneAndUpdate({
|
|
105
|
+
roleName: { $eq: params.roleName.$eq },
|
|
106
|
+
permissions: { $ne: params.permission }
|
|
107
|
+
}, {
|
|
108
|
+
$push: {
|
|
109
|
+
permissions: {
|
|
110
|
+
$each: [params.permission],
|
|
111
|
+
$sort: 1
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}, {
|
|
115
|
+
new: true,
|
|
116
|
+
projection: { _id: 1 }
|
|
117
|
+
})
|
|
118
|
+
.lean()
|
|
119
|
+
.exec();
|
|
120
|
+
});
|
|
121
|
+
}
|
|
102
122
|
}
|
|
103
123
|
exports.RoleRepo = RoleRepo;
|
|
@@ -251,8 +251,10 @@ class StockHolderRepo {
|
|
|
251
251
|
return __awaiter(this, void 0, void 0, function* () {
|
|
252
252
|
const key = StockHolderRepo.createKey(params);
|
|
253
253
|
const existingRedisKeyCount = yield this.redisClient.exists(key);
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
if (typeof existingRedisKeyCount !== 'number') {
|
|
255
|
+
throw new factory.errors.Internal(`unexpected existingKeyCount: ${typeof existingRedisKeyCount}`);
|
|
256
|
+
}
|
|
257
|
+
return existingRedisKeyCount > 0;
|
|
256
258
|
});
|
|
257
259
|
}
|
|
258
260
|
checkIfConflicted(params) {
|
package/package.json
CHANGED