@ubs-platform/greenhat-webservice 1.4.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/_monaembed/@ubs-platform/greenhat-entity-mongo/index.d.ts +63 -0
- package/_monaembed/@ubs-platform/greenhat-entity-mongo/index.js +165 -0
- package/_monaembed/@ubs-platform/greenhat-entity-mongo/index.js.map +1 -0
- package/_monaembed/@ubs-platform/greenhat-entity-mongo/package.json +1 -0
- package/_monaembed/@ubs-platform/greenhat-entity-mongo/tsconfig.lib-publish.tsbuildinfo +1 -0
- package/controller/document.controller.d.ts +19 -0
- package/controller/document.controller.js +97 -0
- package/controller/document.controller.js.map +1 -0
- package/controller/project.controller.d.ts +8 -0
- package/controller/project.controller.js +32 -0
- package/controller/project.controller.js.map +1 -0
- package/greenhat-webservice.module.d.ts +2 -0
- package/greenhat-webservice.module.js +34 -0
- package/greenhat-webservice.module.js.map +1 -0
- package/index.d.ts +5 -0
- package/index.js +22 -0
- package/index.js.map +1 -0
- package/package.json +1 -0
- package/service/document.service.d.ts +26 -0
- package/service/document.service.js +343 -0
- package/service/document.service.js.map +1 -0
- package/service/project.service.d.ts +21 -0
- package/service/project.service.js +141 -0
- package/service/project.service.js.map +1 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ProjectService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
18
|
+
const mongoose_2 = require("mongoose");
|
|
19
|
+
const crud_base_1 = require("@ubs-platform/crud-base");
|
|
20
|
+
const greenhat_entity_mongo_1 = require("../_monaembed/@ubs-platform/greenhat-entity-mongo");
|
|
21
|
+
const users_microservice_helper_1 = require("@ubs-platform/users-microservice-helper");
|
|
22
|
+
const users_common_1 = require("@ubs-platform/users-common");
|
|
23
|
+
const rxjs_1 = require("rxjs");
|
|
24
|
+
const GREENHAT_ENTITY_GROUP = 'GREENHAT';
|
|
25
|
+
const GREENHAT_ENTITY_NAME_PROJECT = 'PROJECT';
|
|
26
|
+
const PROJECT_READ_CAPABILITIES = ['OWNER', 'EDITOR', 'VIEWER'];
|
|
27
|
+
let ProjectService = class ProjectService extends crud_base_1.BaseCrudService {
|
|
28
|
+
constructor(projectModel, eoService) {
|
|
29
|
+
super(new crud_base_1.MongoRepositoryWrap(projectModel));
|
|
30
|
+
this.projectModel = projectModel;
|
|
31
|
+
this.eoService = eoService;
|
|
32
|
+
}
|
|
33
|
+
generateNewModel() {
|
|
34
|
+
return new this.projectModel();
|
|
35
|
+
}
|
|
36
|
+
getIdFieldNameFromInput(i) {
|
|
37
|
+
return i._id;
|
|
38
|
+
}
|
|
39
|
+
getIdFieldNameFromModel(i) {
|
|
40
|
+
return i._id.toString();
|
|
41
|
+
}
|
|
42
|
+
async toOutput(m) {
|
|
43
|
+
return {
|
|
44
|
+
_id: m._id.toString(),
|
|
45
|
+
slug: m.slug,
|
|
46
|
+
title: m.title,
|
|
47
|
+
description: m.description,
|
|
48
|
+
visibility: m.visibility,
|
|
49
|
+
deactivated: m.deactivated,
|
|
50
|
+
createdBy: m.createdBy,
|
|
51
|
+
updatedBy: m.updatedBy,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
moveIntoModel(model, i) {
|
|
55
|
+
model.slug = (i.slug || this.generateTimeSlug()).trim();
|
|
56
|
+
model.title = i.title?.trim();
|
|
57
|
+
model.description = i.description?.trim() || '';
|
|
58
|
+
model.visibility = i.visibility || 'private';
|
|
59
|
+
return model;
|
|
60
|
+
}
|
|
61
|
+
async beforeCreateOrEdit(model, input, mode, user) {
|
|
62
|
+
if (mode === 'CREATE') {
|
|
63
|
+
model.createdBy = user?.id || 'system';
|
|
64
|
+
model.deactivated = false;
|
|
65
|
+
model.slug = (input.slug || this.generateTimeSlug()).trim();
|
|
66
|
+
}
|
|
67
|
+
model.updatedBy = user?.id || model.updatedBy;
|
|
68
|
+
}
|
|
69
|
+
async searchParams(s, u) {
|
|
70
|
+
const where = {};
|
|
71
|
+
if (s?._id) {
|
|
72
|
+
where._id = s._id;
|
|
73
|
+
}
|
|
74
|
+
if (s?.slug) {
|
|
75
|
+
where.slug = s.slug;
|
|
76
|
+
}
|
|
77
|
+
if (s?.titleContains) {
|
|
78
|
+
where.title = { $regex: `.*${s.titleContains}.*`, $options: 'i' };
|
|
79
|
+
}
|
|
80
|
+
if (s?.deactivated === 'ONLY_DEACTIVATED') {
|
|
81
|
+
where.deactivated = true;
|
|
82
|
+
}
|
|
83
|
+
else if (s?.deactivated === 'ALL') {
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
where.deactivated = false;
|
|
87
|
+
}
|
|
88
|
+
if (s?.admin !== 'true') {
|
|
89
|
+
if (!u) {
|
|
90
|
+
throw new common_1.ForbiddenException('User information is required for search');
|
|
91
|
+
}
|
|
92
|
+
const ownedIds = await (0, rxjs_1.lastValueFrom)(this.eoService.searchOwnershipEntityIdsByUser({
|
|
93
|
+
entityGroup: GREENHAT_ENTITY_GROUP,
|
|
94
|
+
entityName: GREENHAT_ENTITY_NAME_PROJECT,
|
|
95
|
+
userId: u.id,
|
|
96
|
+
...(s?.entityOwnershipGroupId
|
|
97
|
+
? { entityOwnershipGroupId: s.entityOwnershipGroupId }
|
|
98
|
+
: {}),
|
|
99
|
+
requestedCapabilities: [[users_common_1.Capability.OWNER], [users_common_1.Capability.EDIT], [users_common_1.Capability.VIEW]],
|
|
100
|
+
}));
|
|
101
|
+
where._id = {
|
|
102
|
+
$in: ownedIds.length > 0 ? ownedIds : ['000000000000000000000000'],
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return where;
|
|
106
|
+
}
|
|
107
|
+
async afterCreate(m, input, user) {
|
|
108
|
+
if (!user || !m._id) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
await this.eoService.insertOwnership({
|
|
112
|
+
entityGroup: GREENHAT_ENTITY_GROUP,
|
|
113
|
+
entityName: GREENHAT_ENTITY_NAME_PROJECT,
|
|
114
|
+
entityId: m._id,
|
|
115
|
+
overriderRoles: [],
|
|
116
|
+
userCapabilities: [{ userId: user.id, capabilities: [users_common_1.Capability.OWNER] }],
|
|
117
|
+
entityOwnershipGroupId: input.entityOwnershipGroupId,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
async remove(id, user) {
|
|
121
|
+
const existing = await this.projectModel.findById(id).exec();
|
|
122
|
+
if (!existing) {
|
|
123
|
+
throw new common_1.NotFoundException('Project not found');
|
|
124
|
+
}
|
|
125
|
+
existing.deactivated = true;
|
|
126
|
+
existing.updatedBy = user?.id || existing.updatedBy;
|
|
127
|
+
await existing.save();
|
|
128
|
+
return this.toOutput(existing);
|
|
129
|
+
}
|
|
130
|
+
generateTimeSlug() {
|
|
131
|
+
return new Date().toISOString().replace(/[-:.TZ]/g, '');
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
exports.ProjectService = ProjectService;
|
|
135
|
+
exports.ProjectService = ProjectService = __decorate([
|
|
136
|
+
(0, common_1.Injectable)(),
|
|
137
|
+
__param(0, (0, mongoose_1.InjectModel)(greenhat_entity_mongo_1.DocProject.name)),
|
|
138
|
+
__metadata("design:paramtypes", [mongoose_2.Model,
|
|
139
|
+
users_microservice_helper_1.EntityOwnershipService])
|
|
140
|
+
], ProjectService);
|
|
141
|
+
//# sourceMappingURL=project.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.service.js","sourceRoot":"","sources":["../../../../../../libs/greenhat-webservice/src/service/project.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAmF;AACnF,+CAA+C;AAC/C,uCAA8C;AAC9C,uDAA+E;AAK/E,+EAAiE;AACjE,uFAEiD;AACjD,6DAA4E;AAC5E,+BAAqC;AAErC,MAAM,qBAAqB,GAAG,UAAU,CAAC;AACzC,MAAM,4BAA4B,GAAG,SAAS,CAAC;AAC/C,MAAM,yBAAyB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAGzD,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,2BAMnC;IACC,YAEmB,YAA+B,EAC/B,SAAiC;QAElD,KAAK,CAAC,IAAI,+BAAmB,CAAa,YAAY,CAAC,CAAC,CAAC;QAHxC,iBAAY,GAAZ,YAAY,CAAmB;QAC/B,cAAS,GAAT,SAAS,CAAwB;IAGpD,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;IACjC,CAAC;IAED,uBAAuB,CAAC,CAAqB;QAC3C,OAAO,CAAC,CAAC,GAAI,CAAC;IAChB,CAAC;IAED,uBAAuB,CAAC,CAAa;QACnC,OAAO,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,CAAa;QAC1B,OAAO;YACL,GAAG,EAAE,CAAC,CAAC,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