@kominal/common-nestjs 0.0.27 → 0.0.29

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,65 @@
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.TenantService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const mongoose_1 = require("@nestjs/mongoose");
18
+ const membership_entity_1 = require("../entities/membership.entity");
19
+ const tenant_entity_1 = require("../entities/tenant.entity");
20
+ const entity_service_helper_1 = require("../helpers/entity-service.helper");
21
+ const entity_model_1 = require("../models/entity.model");
22
+ let TenantService = class TenantService extends entity_service_helper_1.EntityService {
23
+ constructor(tenantModel, membershipModel) {
24
+ super(tenantModel, { technicalKeys: entity_model_1.TECHNICAL_KEYS_BASE_ENTITY });
25
+ this.tenantModel = tenantModel;
26
+ this.membershipModel = membershipModel;
27
+ }
28
+ async createForUser(userContext, request) {
29
+ const { name } = request;
30
+ const tenant = await this.create(userContext, {}, { name });
31
+ await this.membershipModel.create((0, entity_service_helper_1.created)(userContext, {
32
+ tenantId: tenant.uuid,
33
+ userId: userContext.userId,
34
+ email: userContext.email,
35
+ status: membership_entity_1.MembershipStatus.ACTIVE,
36
+ }));
37
+ return tenant;
38
+ }
39
+ async listForUser(userContext, select) {
40
+ if (userContext.admin) {
41
+ return this.tenantModel
42
+ .find()
43
+ .select(select || '')
44
+ .exec();
45
+ }
46
+ const memberships = await this.membershipModel.find({ userId: userContext.userId });
47
+ return this.tenantModel.find({ uuid: { $in: memberships.map((membership) => membership.tenantId) } });
48
+ }
49
+ async updateForUser(userContext, tenantId, body) {
50
+ const tenant = await this.tenantModel.findOne({ uuid: tenantId }).orFail(new common_1.HttpException('Tenant not found', 404));
51
+ tenant.name = body.name;
52
+ tenant.logo = body.logo;
53
+ tenant.updatedAt = new Date();
54
+ tenant.updatedBy = userContext.email;
55
+ await tenant.save();
56
+ }
57
+ };
58
+ exports.TenantService = TenantService;
59
+ exports.TenantService = TenantService = __decorate([
60
+ (0, common_1.Injectable)(),
61
+ __param(0, (0, mongoose_1.InjectModel)(tenant_entity_1.Tenant.name)),
62
+ __param(1, (0, mongoose_1.InjectModel)(membership_entity_1.Membership.name)),
63
+ __metadata("design:paramtypes", [Object, Object])
64
+ ], TenantService);
65
+ //# sourceMappingURL=tenant.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant.service.js","sourceRoot":"","sources":["../../src/services/tenant.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2D;AAC3D,+CAA+C;AAC/C,qEAA8F;AAC9F,6DAA0G;AAE1G,4EAAkG;AAClG,yDAAoE;AAG7D,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,qCAAiD;IAClF,YACoC,WAAwB,EACpB,eAAgC;QAEtE,KAAK,CAAC,WAAW,EAAE,EAAE,aAAa,EAAE,yCAA0B,EAAE,CAAC,CAAC;QAHhC,gBAAW,GAAX,WAAW,CAAa;QACpB,oBAAe,GAAf,eAAe,CAAiB;IAGxE,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,WAAwB,EAAE,OAA4B;QAC/E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