easywork-common-lib 1.0.1063 → 1.0.1064

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.
@@ -2,6 +2,7 @@ import { Plan } from './plan.entity';
2
2
  import { BaseEntityOnlyEssential } from '../../common/database/base.entity';
3
3
  import { Group } from '../group.entity';
4
4
  import { PaymentHistory } from './payment-history.entity';
5
+ import { User } from '../user.entity';
5
6
  export declare enum SubscriptionStatus {
6
7
  ACTIVE = "active",
7
8
  TRIALING = "trialing",
@@ -9,7 +10,8 @@ export declare enum SubscriptionStatus {
9
10
  CANCELED = "canceled",
10
11
  ENDED = "ended",
11
12
  FREE = "free",
12
- PENDING_PAYMENT = "pending_payment"
13
+ PENDING_PAYMENT = "pending_payment",
14
+ PAUSED = "paused"
13
15
  }
14
16
  export declare class Subscription extends BaseEntityOnlyEssential {
15
17
  groupId: string;
@@ -21,7 +23,10 @@ export declare class Subscription extends BaseEntityOnlyEssential {
21
23
  canceledAt: Date | null;
22
24
  accessEndsAt: Date | null;
23
25
  paymentGatewaySubscriptionId: string | null;
26
+ note?: string;
27
+ cancelReason?: string;
24
28
  paymentHistory: PaymentHistory;
25
29
  group: Group;
26
30
  plan: Plan;
31
+ canceledBy: User;
27
32
  }
@@ -16,6 +16,7 @@ const plan_entity_1 = require("./plan.entity");
16
16
  const base_entity_1 = require("../../common/database/base.entity");
17
17
  const group_entity_1 = require("../group.entity");
18
18
  const payment_history_entity_1 = require("./payment-history.entity");
19
+ const user_entity_1 = require("../user.entity");
19
20
  var SubscriptionStatus;
20
21
  (function (SubscriptionStatus) {
21
22
  SubscriptionStatus["ACTIVE"] = "active";
@@ -25,6 +26,7 @@ var SubscriptionStatus;
25
26
  SubscriptionStatus["ENDED"] = "ended";
26
27
  SubscriptionStatus["FREE"] = "free";
27
28
  SubscriptionStatus["PENDING_PAYMENT"] = "pending_payment";
29
+ SubscriptionStatus["PAUSED"] = "paused";
28
30
  })(SubscriptionStatus || (exports.SubscriptionStatus = SubscriptionStatus = {}));
29
31
  let Subscription = class Subscription extends base_entity_1.BaseEntityOnlyEssential {
30
32
  groupId;
@@ -36,9 +38,12 @@ let Subscription = class Subscription extends base_entity_1.BaseEntityOnlyEssent
36
38
  canceledAt;
37
39
  accessEndsAt;
38
40
  paymentGatewaySubscriptionId;
41
+ note;
42
+ cancelReason;
39
43
  paymentHistory;
40
44
  group;
41
45
  plan;
46
+ canceledBy;
42
47
  };
43
48
  exports.Subscription = Subscription;
44
49
  __decorate([
@@ -114,6 +119,22 @@ __decorate([
114
119
  }),
115
120
  __metadata("design:type", String)
116
121
  ], Subscription.prototype, "paymentGatewaySubscriptionId", void 0);
122
+ __decorate([
123
+ (0, typeorm_1.Column)({ type: 'text', nullable: true }),
124
+ (0, swagger_1.ApiProperty)({
125
+ description: 'Additional note or comment about the subscription',
126
+ nullable: true,
127
+ }),
128
+ __metadata("design:type", String)
129
+ ], Subscription.prototype, "note", void 0);
130
+ __decorate([
131
+ (0, typeorm_1.Column)({ type: 'varchar', length: 255, nullable: true }),
132
+ (0, swagger_1.ApiProperty)({
133
+ description: 'Reason for subscription cancellation',
134
+ nullable: true,
135
+ }),
136
+ __metadata("design:type", String)
137
+ ], Subscription.prototype, "cancelReason", void 0);
117
138
  __decorate([
118
139
  (0, typeorm_1.OneToMany)(() => payment_history_entity_1.PaymentHistory, paymentHistory => paymentHistory.subscription),
119
140
  __metadata("design:type", payment_history_entity_1.PaymentHistory)
@@ -128,6 +149,15 @@ __decorate([
128
149
  (0, typeorm_1.JoinColumn)({ name: 'plan_id' }),
129
150
  __metadata("design:type", plan_entity_1.Plan)
130
151
  ], Subscription.prototype, "plan", void 0);
152
+ __decorate([
153
+ (0, typeorm_1.ManyToOne)(() => user_entity_1.User, { nullable: true }),
154
+ (0, typeorm_1.JoinColumn)({ name: 'canceled_by' }),
155
+ (0, swagger_1.ApiProperty)({
156
+ description: 'Usuario que solicitó la cancelación de la suscripción',
157
+ nullable: true,
158
+ }),
159
+ __metadata("design:type", user_entity_1.User)
160
+ ], Subscription.prototype, "canceledBy", void 0);
131
161
  exports.Subscription = Subscription = __decorate([
132
162
  (0, typeorm_1.Entity)('subscriptions')
133
163
  ], Subscription);
@@ -1 +1 @@
1
- {"version":3,"file":"subscription.entity.js","sourceRoot":"","sources":["../../../src/entities/subscriptions/subscription.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAA2E;AAC3E,6CAA8C;AAC9C,+CAAqC;AACrC,mEAA4E;AAC5E,kDAAwC;AACxC,qEAA0D;AAE1D,IAAY,kBAQX;AARD,WAAY,kBAAkB;IAC5B,uCAAiB,CAAA;IACjB,2CAAqB,CAAA;IACrB,2CAAqB,CAAA;IACrB,2CAAqB,CAAA;IACrB,qCAAe,CAAA;IACf,mCAAa,CAAA;IACb,yDAAmC,CAAA;AACrC,CAAC,EARW,kBAAkB,kCAAlB,kBAAkB,QAQ7B;AAGM,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,qCAAuB;IAGvD,OAAO,CAAS;IAIhB,MAAM,CAAS;IAQf,kBAAkB,CAAqB;IAQvC,qBAAqB,CAAc;IAQnC,mBAAmB,CAAc;IAQjC,WAAW,CAAc;IAQzB,UAAU,CAAc;IAQxB,YAAY,CAAc;IAQ1B,4BAA4B,CAAgB;IAG5C,cAAc,CAAiB;IAI/B,KAAK,CAAQ;IAIb,IAAI,CAAO;CACZ,CAAA;AA3EY,oCAAY;AAGvB;IAFC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACxC,IAAA,qBAAW,EAAC,EAAE,WAAW,EAAE,oCAAoC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;;6CACjE;AAIhB;IAFC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IACzC,IAAA,qBAAW,EAAC,EAAE,WAAW,EAAE,qCAAqC,EAAE,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I,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;IAC1E,IAAA,oBAAU,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;8BAC1B,kBAAI;0CAAC;AAQX;IANC,IAAA,mBAAS,EAAC,GAAG,EAAE,CAAC,kBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACzC,IAAA,oBAAU,EAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;IACnC,IAAA,qBAAW,EAAC;QACX,WAAW,EAAE,uDAAuD;QACpE,QAAQ,EAAE,IAAI;KACf,CAAC;8BACU,kBAAI;gDAAC;uBAhGN,YAAY;IADxB,IAAA,gBAAM,EAAC,eAAe,CAAC;GACX,YAAY,CAiGxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easywork-common-lib",
3
- "version": "1.0.1063",
3
+ "version": "1.0.1064",
4
4
  "description": "Librería común de Easywork",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,35 +0,0 @@
1
- export declare class AppModule {
2
- }
3
- import { Repository } from 'typeorm';
4
- import { ContactAuthorizationService, ResourceAuthorizationFactory, PermissionAction } from 'easywork-common-lib/modules';
5
- import { Contact, SubGroup, User } from 'easywork-common-lib/entities';
6
- export declare class ContactService {
7
- private contactRepository;
8
- private subGroupRepository;
9
- private readonly contactAuthService;
10
- private readonly authFactory;
11
- constructor(contactRepository: Repository<Contact>, subGroupRepository: Repository<SubGroup>, contactAuthService: ContactAuthorizationService, authFactory: ResourceAuthorizationFactory);
12
- getAllContacts(user: User): Promise<Contact[]>;
13
- getContactById(id: string, user: User): Promise<Contact>;
14
- }
15
- export declare class PoliciesService {
16
- private subGroupRepository;
17
- private readonly authFactory;
18
- constructor(subGroupRepository: Repository<SubGroup>, authFactory: ResourceAuthorizationFactory);
19
- getAllPolicies(user: User): Promise<any>;
20
- }
21
- import { AuthorizationService } from 'easywork-common-lib/modules';
22
- export declare class GenericResourceService {
23
- private readonly authService;
24
- constructor(authService: AuthorizationService);
25
- checkUserAccess(user: User, action: PermissionAction, resource: string): Promise<any>;
26
- validateMultiplePermissions(user: User): Promise<any>;
27
- }
28
- export declare class ContactController {
29
- private readonly contactService;
30
- constructor(contactService: ContactService);
31
- getAllContacts(user: User): Promise<Contact[]>;
32
- getContactById(id: string, user: User): Promise<Contact>;
33
- }
34
- export declare class ContactModule {
35
- }
@@ -1,180 +0,0 @@
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
- var _a, _b, _c, _d, _e, _f;
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.ContactModule = exports.ContactController = exports.GenericResourceService = exports.PoliciesService = exports.ContactService = exports.AppModule = void 0;
17
- const common_1 = require("@nestjs/common");
18
- const modules_1 = require("easywork-common-lib/modules");
19
- let AppModule = class AppModule {
20
- };
21
- exports.AppModule = AppModule;
22
- exports.AppModule = AppModule = __decorate([
23
- (0, common_1.Module)({
24
- imports: [
25
- modules_1.AuthorizationModule,
26
- modules_1.AuthorizationModule.forRoot({
27
- cache: {
28
- ttl: 600,
29
- max: 2000,
30
- },
31
- }),
32
- ],
33
- })
34
- ], AppModule);
35
- const common_2 = require("@nestjs/common");
36
- const typeorm_1 = require("typeorm");
37
- const typeorm_2 = require("@nestjs/typeorm");
38
- const modules_2 = require("easywork-common-lib/modules");
39
- const entities_1 = require("easywork-common-lib/entities");
40
- let ContactService = class ContactService {
41
- contactRepository;
42
- subGroupRepository;
43
- contactAuthService;
44
- authFactory;
45
- constructor(contactRepository, subGroupRepository, contactAuthService, authFactory) {
46
- this.contactRepository = contactRepository;
47
- this.subGroupRepository = subGroupRepository;
48
- this.contactAuthService = contactAuthService;
49
- this.authFactory = authFactory;
50
- }
51
- async getAllContacts(user) {
52
- const queryBuilder = this.contactRepository
53
- .createQueryBuilder('contact');
54
- await this.contactAuthService.applyContactPermissionFilters(queryBuilder, user, {
55
- action: modules_2.PermissionAction.READ,
56
- subGroupRepository: this.subGroupRepository,
57
- });
58
- return queryBuilder.getMany();
59
- }
60
- async getContactById(id, user) {
61
- const contact = await this.contactRepository.findOne({ where: { id } });
62
- if (!contact) {
63
- throw new Error('Contact not found');
64
- }
65
- await this.contactAuthService.validateContactAccess(user, modules_2.PermissionAction.READ, contact, this.subGroupRepository);
66
- return contact;
67
- }
68
- };
69
- exports.ContactService = ContactService;
70
- exports.ContactService = ContactService = __decorate([
71
- (0, common_2.Injectable)(),
72
- __param(0, (0, typeorm_2.InjectRepository)(entities_1.Contact)),
73
- __param(1, (0, typeorm_2.InjectRepository)(entities_1.SubGroup)),
74
- __metadata("design:paramtypes", [typeorm_1.Repository,
75
- typeorm_1.Repository, typeof (_a = typeof modules_2.ContactAuthorizationService !== "undefined" && modules_2.ContactAuthorizationService) === "function" ? _a : Object, typeof (_b = typeof modules_2.ResourceAuthorizationFactory !== "undefined" && modules_2.ResourceAuthorizationFactory) === "function" ? _b : Object])
76
- ], ContactService);
77
- let PoliciesService = class PoliciesService {
78
- subGroupRepository;
79
- authFactory;
80
- constructor(subGroupRepository, authFactory) {
81
- this.subGroupRepository = subGroupRepository;
82
- this.authFactory = authFactory;
83
- }
84
- async getAllPolicies(user) {
85
- const queryBuilder = this.policyRepository
86
- .createQueryBuilder('policy');
87
- const policyAuth = this.authFactory.forPolicy(this.subGroupRepository);
88
- await policyAuth.applyPermissionFilters(queryBuilder, user, {
89
- action: modules_2.PermissionAction.READ,
90
- });
91
- return queryBuilder.getMany();
92
- }
93
- };
94
- exports.PoliciesService = PoliciesService;
95
- exports.PoliciesService = PoliciesService = __decorate([
96
- (0, common_2.Injectable)(),
97
- __param(0, (0, typeorm_2.InjectRepository)(entities_1.SubGroup)),
98
- __metadata("design:paramtypes", [typeorm_1.Repository, typeof (_c = typeof modules_2.ResourceAuthorizationFactory !== "undefined" && modules_2.ResourceAuthorizationFactory) === "function" ? _c : Object])
99
- ], PoliciesService);
100
- const modules_3 = require("easywork-common-lib/modules");
101
- let GenericResourceService = class GenericResourceService {
102
- authService;
103
- constructor(authService) {
104
- this.authService = authService;
105
- }
106
- async checkUserAccess(user, action, resource) {
107
- const result = await this.authService.canAccess({
108
- user,
109
- action,
110
- resource,
111
- });
112
- return result.allowed;
113
- }
114
- async validateMultiplePermissions(user) {
115
- const results = await this.authService.canAccessMultiple([
116
- { user, action: modules_2.PermissionAction.READ, resource: 'contact' },
117
- { user, action: modules_2.PermissionAction.CREATE, resource: 'lead' },
118
- { user, action: modules_2.PermissionAction.UPDATE, resource: 'policy' },
119
- ]);
120
- return results;
121
- }
122
- };
123
- exports.GenericResourceService = GenericResourceService;
124
- exports.GenericResourceService = GenericResourceService = __decorate([
125
- (0, common_2.Injectable)(),
126
- __metadata("design:paramtypes", [typeof (_d = typeof modules_3.AuthorizationService !== "undefined" && modules_3.AuthorizationService) === "function" ? _d : Object])
127
- ], GenericResourceService);
128
- const common_3 = require("@nestjs/common");
129
- const modules_4 = require("easywork-common-lib/modules");
130
- const your_auth_decorator_1 = require("your-auth-decorator");
131
- let ContactController = class ContactController {
132
- contactService;
133
- constructor(contactService) {
134
- this.contactService = contactService;
135
- }
136
- async getAllContacts(user) {
137
- return this.contactService.getAllContacts(user);
138
- }
139
- async getContactById(id, user) {
140
- return this.contactService.getContactById(id, user);
141
- }
142
- };
143
- exports.ContactController = ContactController;
144
- __decorate([
145
- (0, common_3.Get)(),
146
- __param(0, (0, your_auth_decorator_1.CurrentUser)()),
147
- __metadata("design:type", Function),
148
- __metadata("design:paramtypes", [typeof (_e = typeof entities_1.User !== "undefined" && entities_1.User) === "function" ? _e : Object]),
149
- __metadata("design:returntype", Promise)
150
- ], ContactController.prototype, "getAllContacts", null);
151
- __decorate([
152
- (0, common_3.Get)(':id'),
153
- __param(0, (0, common_3.Param)('id')),
154
- __param(1, (0, your_auth_decorator_1.CurrentUser)()),
155
- __metadata("design:type", Function),
156
- __metadata("design:paramtypes", [String, typeof (_f = typeof entities_1.User !== "undefined" && entities_1.User) === "function" ? _f : Object]),
157
- __metadata("design:returntype", Promise)
158
- ], ContactController.prototype, "getContactById", null);
159
- exports.ContactController = ContactController = __decorate([
160
- (0, common_3.Controller)('contacts'),
161
- (0, common_3.UseGuards)(modules_4.EnhancedRolesPolicyGuard),
162
- __metadata("design:paramtypes", [ContactService])
163
- ], ContactController);
164
- let ContactModule = class ContactModule {
165
- };
166
- exports.ContactModule = ContactModule;
167
- exports.ContactModule = ContactModule = __decorate([
168
- (0, common_1.Module)({
169
- imports: [
170
- TypeOrmModule.forFeature([entities_1.Contact, entities_1.Lead, Policy]),
171
- ],
172
- controllers: [ContactController],
173
- providers: [
174
- ContactService,
175
- PoliciesService,
176
- GenericResourceService,
177
- ],
178
- })
179
- ], ContactModule);
180
- //# sourceMappingURL=usage-example.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"usage-example.js","sourceRoot":"","sources":["../../../src/modules/authorization/usage-example.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAiBA,2CAAwC;AACxC,yDAAkE;AAoB3D,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,8BAAS;oBAAT,SAAS;IAlBrB,IAAA,eAAM,EAAC;QAC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