@grapadigital/shared-schemas 1.0.173 → 1.0.175

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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TriggerSchema = exports.Trigger = exports.TriggerRecipient = void 0;
13
+ const mongoose_1 = require("@nestjs/mongoose");
14
+ const mongoose_2 = require("mongoose");
15
+ class TriggerRecipient {
16
+ }
17
+ __decorate([
18
+ (0, mongoose_1.Prop)({ type: String, enum: ['user', 'group'], required: true }),
19
+ __metadata("design:type", String)
20
+ ], TriggerRecipient.prototype, "type", void 0);
21
+ __decorate([
22
+ (0, mongoose_1.Prop)({ type: mongoose_2.Types.ObjectId, required: true }),
23
+ __metadata("design:type", mongoose_2.Types.ObjectId)
24
+ ], TriggerRecipient.prototype, "refId", void 0);
25
+ exports.TriggerRecipient = TriggerRecipient;
26
+ let Trigger = class Trigger {
27
+ };
28
+ __decorate([
29
+ (0, mongoose_1.Prop)({ required: true, trim: true }),
30
+ __metadata("design:type", String)
31
+ ], Trigger.prototype, "event", void 0);
32
+ __decorate([
33
+ (0, mongoose_1.Prop)({ type: mongoose_2.Types.ObjectId, required: true, index: true }),
34
+ __metadata("design:type", mongoose_2.Types.ObjectId)
35
+ ], Trigger.prototype, "organizationId", void 0);
36
+ __decorate([
37
+ (0, mongoose_1.Prop)({ required: true, trim: true }),
38
+ __metadata("design:type", String)
39
+ ], Trigger.prototype, "name", void 0);
40
+ __decorate([
41
+ (0, mongoose_1.Prop)({ default: true }),
42
+ __metadata("design:type", Boolean)
43
+ ], Trigger.prototype, "active", void 0);
44
+ __decorate([
45
+ (0, mongoose_1.Prop)({ required: true }),
46
+ __metadata("design:type", String)
47
+ ], Trigger.prototype, "title", void 0);
48
+ __decorate([
49
+ (0, mongoose_1.Prop)({ required: true }),
50
+ __metadata("design:type", String)
51
+ ], Trigger.prototype, "inAppBody", void 0);
52
+ __decorate([
53
+ (0, mongoose_1.Prop)({ required: true }),
54
+ __metadata("design:type", String)
55
+ ], Trigger.prototype, "emailTemplate", void 0);
56
+ __decorate([
57
+ (0, mongoose_1.Prop)({ type: [TriggerRecipient], default: [] }),
58
+ __metadata("design:type", Array)
59
+ ], Trigger.prototype, "recipients", void 0);
60
+ Trigger = __decorate([
61
+ (0, mongoose_1.Schema)({ timestamps: true, collection: 'trigger' })
62
+ ], Trigger);
63
+ exports.Trigger = Trigger;
64
+ exports.TriggerSchema = mongoose_1.SchemaFactory.createForClass(Trigger);
65
+ exports.TriggerSchema.index({ event: 1, organizationId: 1 }, { unique: true });
@@ -23,94 +23,39 @@
23
23
  /// <reference types="mongoose/types/schematypes" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  /// <reference types="mongoose/types/inferrawdoctype" />
26
- import { HydratedDocument, Schema as MongooseSchema, Types } from 'mongoose';
26
+ import { HydratedDocument, Types } from 'mongoose';
27
27
  export type UserDocument = HydratedDocument<User>;
28
- export declare class Address {
29
- zipcode: string;
30
- city: string;
31
- state: string;
32
- street: string;
33
- number: string;
34
- complement: string;
28
+ export declare enum OrganizationTeam {
29
+ SERVICE = "service",
30
+ ADMIN = "admin",
31
+ ARTISTIC = "artistic",
32
+ FINANCIAL = "financial",
33
+ COMERCIAL = "comercial"
35
34
  }
36
- export declare const AddressSchema: MongooseSchema<Address, import("mongoose").Model<Address, any, any, any, import("mongoose").Document<unknown, any, Address, any, {}> & Address & {
37
- _id: Types.ObjectId;
38
- } & {
39
- __v: number;
40
- }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, Address, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<Address>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<Address> & {
41
- _id: Types.ObjectId;
42
- } & {
43
- __v: number;
44
- }>;
45
- export declare class Company {
46
- legalName: string;
47
- document: string;
48
- bank: string;
49
- agency: string;
50
- account: string;
51
- digit: string;
52
- pix: string;
53
- email: string;
54
- omieGrapaId?: string;
55
- omieOmaId?: string;
56
- }
57
- export declare const CompanySchema: MongooseSchema<Company, import("mongoose").Model<Company, any, any, any, import("mongoose").Document<unknown, any, Company, any, {}> & Company & {
58
- _id: Types.ObjectId;
59
- } & {
60
- __v: number;
61
- }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, Company, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<Company>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<Company> & {
62
- _id: Types.ObjectId;
63
- } & {
64
- __v: number;
65
- }>;
66
- export declare class Individual {
67
- rg: string;
68
- cpf: string;
69
- birthday: Date;
70
- maritalStatus: string;
71
- nationality: string;
72
- profession: string;
35
+ export declare enum UserRole {
36
+ ADMIN = "admin",
37
+ USER = "user",
38
+ CLIENT = "client",
39
+ INFLUENCER = "influencer"
73
40
  }
74
- export declare const IndividualSchema: MongooseSchema<Individual, import("mongoose").Model<Individual, any, any, any, import("mongoose").Document<unknown, any, Individual, any, {}> & Individual & {
75
- _id: Types.ObjectId;
76
- } & {
77
- __v: number;
78
- }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, Individual, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<Individual>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<Individual> & {
79
- _id: Types.ObjectId;
80
- } & {
81
- __v: number;
82
- }>;
83
41
  export declare class User {
84
- _id?: Types.ObjectId;
42
+ organization: Types.ObjectId;
43
+ email: string;
85
44
  name: string;
86
- email?: string;
87
- phone?: string;
88
- picture?: string;
89
- address?: Address;
90
- company?: Company;
91
- individual?: Individual;
45
+ username: string;
46
+ team?: OrganizationTeam;
47
+ role?: UserRole;
48
+ firebaseUid?: string;
49
+ disabled?: boolean;
92
50
  createdAt?: Date;
93
51
  updatedAt?: Date;
94
52
  }
95
- export declare const UserSchema: MongooseSchema<User, import("mongoose").Model<User, any, any, any, import("mongoose").Document<unknown, any, User, any, {}> & User & Required<{
53
+ export declare const UserSchema: import("mongoose").Schema<User, import("mongoose").Model<User, any, any, any, import("mongoose").Document<unknown, any, User, any, {}> & User & {
96
54
  _id: Types.ObjectId;
97
- }> & {
55
+ } & {
98
56
  __v: number;
99
- }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, User, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<User>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<User> & Required<{
57
+ }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, User, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<User>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<User> & {
100
58
  _id: Types.ObjectId;
101
- }> & {
59
+ } & {
102
60
  __v: number;
103
61
  }>;
104
- export declare const UserModel: import("mongoose").Model<User, {}, {}, {}, import("mongoose").Document<unknown, {}, User, {}, import("mongoose").DefaultSchemaOptions> & User & Required<{
105
- _id: Types.ObjectId;
106
- }> & {
107
- __v: number;
108
- }, MongooseSchema<User, import("mongoose").Model<User, any, any, any, import("mongoose").Document<unknown, any, User, any, {}> & User & Required<{
109
- _id: Types.ObjectId;
110
- }> & {
111
- __v: number;
112
- }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, User, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<User>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<User> & Required<{
113
- _id: Types.ObjectId;
114
- }> & {
115
- __v: number;
116
- }>>;
@@ -9,167 +9,62 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.UserModel = exports.UserSchema = exports.User = exports.IndividualSchema = exports.Individual = exports.CompanySchema = exports.Company = exports.AddressSchema = exports.Address = void 0;
12
+ exports.UserSchema = exports.User = exports.UserRole = exports.OrganizationTeam = void 0;
13
13
  const mongoose_1 = require("@nestjs/mongoose");
14
14
  const mongoose_2 = require("mongoose");
15
- let Address = class Address {
16
- };
17
- __decorate([
18
- (0, mongoose_1.Prop)(),
19
- __metadata("design:type", String)
20
- ], Address.prototype, "zipcode", void 0);
21
- __decorate([
22
- (0, mongoose_1.Prop)(),
23
- __metadata("design:type", String)
24
- ], Address.prototype, "city", void 0);
25
- __decorate([
26
- (0, mongoose_1.Prop)(),
27
- __metadata("design:type", String)
28
- ], Address.prototype, "state", void 0);
29
- __decorate([
30
- (0, mongoose_1.Prop)(),
31
- __metadata("design:type", String)
32
- ], Address.prototype, "street", void 0);
33
- __decorate([
34
- (0, mongoose_1.Prop)(),
35
- __metadata("design:type", String)
36
- ], Address.prototype, "number", void 0);
37
- __decorate([
38
- (0, mongoose_1.Prop)(),
39
- __metadata("design:type", String)
40
- ], Address.prototype, "complement", void 0);
41
- Address = __decorate([
42
- (0, mongoose_1.Schema)({ _id: false })
43
- ], Address);
44
- exports.Address = Address;
45
- exports.AddressSchema = mongoose_1.SchemaFactory.createForClass(Address);
46
- let Company = class Company {
47
- };
48
- __decorate([
49
- (0, mongoose_1.Prop)(),
50
- __metadata("design:type", String)
51
- ], Company.prototype, "legalName", void 0);
52
- __decorate([
53
- (0, mongoose_1.Prop)(),
54
- __metadata("design:type", String)
55
- ], Company.prototype, "document", void 0);
56
- __decorate([
57
- (0, mongoose_1.Prop)(),
58
- __metadata("design:type", String)
59
- ], Company.prototype, "bank", void 0);
60
- __decorate([
61
- (0, mongoose_1.Prop)(),
62
- __metadata("design:type", String)
63
- ], Company.prototype, "agency", void 0);
64
- __decorate([
65
- (0, mongoose_1.Prop)(),
66
- __metadata("design:type", String)
67
- ], Company.prototype, "account", void 0);
68
- __decorate([
69
- (0, mongoose_1.Prop)(),
70
- __metadata("design:type", String)
71
- ], Company.prototype, "digit", void 0);
72
- __decorate([
73
- (0, mongoose_1.Prop)(),
74
- __metadata("design:type", String)
75
- ], Company.prototype, "pix", void 0);
76
- __decorate([
77
- (0, mongoose_1.Prop)(),
78
- __metadata("design:type", String)
79
- ], Company.prototype, "email", void 0);
80
- __decorate([
81
- (0, mongoose_1.Prop)({ required: false }),
82
- __metadata("design:type", String)
83
- ], Company.prototype, "omieGrapaId", void 0);
84
- __decorate([
85
- (0, mongoose_1.Prop)({ required: false }),
86
- __metadata("design:type", String)
87
- ], Company.prototype, "omieOmaId", void 0);
88
- Company = __decorate([
89
- (0, mongoose_1.Schema)({ _id: false })
90
- ], Company);
91
- exports.Company = Company;
92
- exports.CompanySchema = mongoose_1.SchemaFactory.createForClass(Company);
93
- let Individual = class Individual {
94
- };
95
- __decorate([
96
- (0, mongoose_1.Prop)(),
97
- __metadata("design:type", String)
98
- ], Individual.prototype, "rg", void 0);
99
- __decorate([
100
- (0, mongoose_1.Prop)(),
101
- __metadata("design:type", String)
102
- ], Individual.prototype, "cpf", void 0);
103
- __decorate([
104
- (0, mongoose_1.Prop)(),
105
- __metadata("design:type", Date)
106
- ], Individual.prototype, "birthday", void 0);
107
- __decorate([
108
- (0, mongoose_1.Prop)(),
109
- __metadata("design:type", String)
110
- ], Individual.prototype, "maritalStatus", void 0);
111
- __decorate([
112
- (0, mongoose_1.Prop)(),
113
- __metadata("design:type", String)
114
- ], Individual.prototype, "nationality", void 0);
115
- __decorate([
116
- (0, mongoose_1.Prop)(),
117
- __metadata("design:type", String)
118
- ], Individual.prototype, "profession", void 0);
119
- Individual = __decorate([
120
- (0, mongoose_1.Schema)({ _id: false })
121
- ], Individual);
122
- exports.Individual = Individual;
123
- exports.IndividualSchema = mongoose_1.SchemaFactory.createForClass(Individual);
15
+ var OrganizationTeam;
16
+ (function (OrganizationTeam) {
17
+ OrganizationTeam["SERVICE"] = "service";
18
+ OrganizationTeam["ADMIN"] = "admin";
19
+ OrganizationTeam["ARTISTIC"] = "artistic";
20
+ OrganizationTeam["FINANCIAL"] = "financial";
21
+ OrganizationTeam["COMERCIAL"] = "comercial";
22
+ })(OrganizationTeam = exports.OrganizationTeam || (exports.OrganizationTeam = {}));
23
+ var UserRole;
24
+ (function (UserRole) {
25
+ UserRole["ADMIN"] = "admin";
26
+ UserRole["USER"] = "user";
27
+ UserRole["CLIENT"] = "client";
28
+ UserRole["INFLUENCER"] = "influencer";
29
+ })(UserRole = exports.UserRole || (exports.UserRole = {}));
124
30
  let User = class User {
125
31
  };
126
32
  __decorate([
127
- (0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.ObjectId, auto: true, required: false }),
33
+ (0, mongoose_1.Prop)({ type: mongoose_2.Types.ObjectId, ref: 'Organization', required: true, index: true }),
128
34
  __metadata("design:type", mongoose_2.Types.ObjectId)
129
- ], User.prototype, "_id", void 0);
35
+ ], User.prototype, "organization", void 0);
130
36
  __decorate([
131
- (0, mongoose_1.Prop)(),
132
- __metadata("design:type", String)
133
- ], User.prototype, "name", void 0);
134
- __decorate([
135
- (0, mongoose_1.Prop)({ required: false }),
37
+ (0, mongoose_1.Prop)({ required: true, trim: true, lowercase: true, index: true }),
136
38
  __metadata("design:type", String)
137
39
  ], User.prototype, "email", void 0);
138
40
  __decorate([
139
- (0, mongoose_1.Prop)({ required: false }),
41
+ (0, mongoose_1.Prop)({ required: true, trim: true }),
140
42
  __metadata("design:type", String)
141
- ], User.prototype, "phone", void 0);
43
+ ], User.prototype, "name", void 0);
142
44
  __decorate([
143
- (0, mongoose_1.Prop)({ required: false }),
45
+ (0, mongoose_1.Prop)({ required: true, trim: true }),
144
46
  __metadata("design:type", String)
145
- ], User.prototype, "picture", void 0);
146
- __decorate([
147
- (0, mongoose_1.Prop)({ type: exports.AddressSchema, required: false }),
148
- __metadata("design:type", Address)
149
- ], User.prototype, "address", void 0);
47
+ ], User.prototype, "username", void 0);
150
48
  __decorate([
151
- (0, mongoose_1.Prop)({ type: exports.CompanySchema, required: false }),
152
- __metadata("design:type", Company)
153
- ], User.prototype, "company", void 0);
49
+ (0, mongoose_1.Prop)({ enum: OrganizationTeam }),
50
+ __metadata("design:type", String)
51
+ ], User.prototype, "team", void 0);
154
52
  __decorate([
155
- (0, mongoose_1.Prop)({ type: exports.IndividualSchema, required: false }),
156
- __metadata("design:type", Individual)
157
- ], User.prototype, "individual", void 0);
53
+ (0, mongoose_1.Prop)({ enum: UserRole }),
54
+ __metadata("design:type", String)
55
+ ], User.prototype, "role", void 0);
158
56
  __decorate([
159
- (0, mongoose_1.Prop)({ default: Date.now, required: false }),
160
- __metadata("design:type", Date)
161
- ], User.prototype, "createdAt", void 0);
57
+ (0, mongoose_1.Prop)({ trim: true }),
58
+ __metadata("design:type", String)
59
+ ], User.prototype, "firebaseUid", void 0);
162
60
  __decorate([
163
- (0, mongoose_1.Prop)({ default: Date.now, required: false }),
164
- __metadata("design:type", Date)
165
- ], User.prototype, "updatedAt", void 0);
61
+ (0, mongoose_1.Prop)({ default: false }),
62
+ __metadata("design:type", Boolean)
63
+ ], User.prototype, "disabled", void 0);
166
64
  User = __decorate([
167
- (0, mongoose_1.Schema)({ timestamps: true })
65
+ (0, mongoose_1.Schema)({ timestamps: true, collection: 'user' })
168
66
  ], User);
169
67
  exports.User = User;
170
68
  exports.UserSchema = mongoose_1.SchemaFactory.createForClass(User);
171
- exports.UserSchema.index({ name: 1 });
172
- exports.UserSchema.index({ 'company.document': 1 });
173
- exports.UserSchema.index({ 'company.legalName': 1 });
174
- exports.UserSchema.index({ createdAt: -1 });
175
- exports.UserModel = (0, mongoose_2.model)('User', exports.UserSchema);
69
+ exports.UserSchema.index({ organization: 1, email: 1 }, { unique: true });
70
+ exports.UserSchema.index({ organization: 1, username: 1 }, { unique: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grapadigital/shared-schemas",
3
- "version": "1.0.173",
3
+ "version": "1.0.175",
4
4
  "description": "Shared Mongoose Schemas",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -18,3 +18,7 @@ export * from './schemas/commission.schema';
18
18
  export * from './schemas/contract.schema';
19
19
  export * from './schemas/benchmark.schema';
20
20
  export * from './schemas/notifications.schema';
21
+ export * from './schemas/organization.schema';
22
+ export * from './schemas/user.schema';
23
+ export * from './schemas/group.schema';
24
+ export * from './schemas/trigger.schema';
@@ -1,6 +1,6 @@
1
1
  import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2
2
  import { HydratedDocument, model as MongooseModel } from 'mongoose';
3
- import { User } from './user.schema';
3
+ import { Party } from './party.schema';
4
4
 
5
5
  export type ClientDocument = HydratedDocument<Client>;
6
6
 
@@ -69,7 +69,7 @@ export class NicheItem {
69
69
  export const NicheItemSchema = SchemaFactory.createForClass(NicheItem);
70
70
 
71
71
  @Schema({ timestamps: true })
72
- export class Client extends User {
72
+ export class Client extends Party {
73
73
  @Prop({ type: [ClusterSchema], default: [] })
74
74
  clusters: Cluster[];
75
75
 
@@ -0,0 +1,23 @@
1
+ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2
+ import { HydratedDocument, Types } from 'mongoose';
3
+
4
+ export type GroupDocument = HydratedDocument<Group>;
5
+
6
+ @Schema({ timestamps: true, collection: 'group' })
7
+ export class Group {
8
+ @Prop({ type: Types.ObjectId, ref: 'Organization', required: true, index: true })
9
+ organization: Types.ObjectId;
10
+
11
+ @Prop({ required: true, trim: true })
12
+ name: string;
13
+
14
+ @Prop({ type: [Types.ObjectId], ref: 'User', default: [] })
15
+ memberIds: Types.ObjectId[];
16
+
17
+ createdAt?: Date;
18
+ updatedAt?: Date;
19
+ }
20
+
21
+ export const GroupSchema = SchemaFactory.createForClass(Group);
22
+
23
+ GroupSchema.index({ organization: 1, name: 1 }, { unique: true });
@@ -1,7 +1,7 @@
1
1
  import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2
2
  import { HydratedDocument, Schema as MongooseSchema, Types, model as MongooseModel } from 'mongoose';
3
3
  import { Profile } from './profile.schema';
4
- import { User } from './user.schema';
4
+ import { Party } from './party.schema';
5
5
 
6
6
  export type InfluencerDocument = HydratedDocument<Influencer>;
7
7
  @Schema({ _id: false })
@@ -34,7 +34,7 @@ export class Note {
34
34
  export const NoteSchema = SchemaFactory.createForClass(Note);
35
35
 
36
36
  @Schema({ timestamps: true })
37
- export class Influencer extends User {
37
+ export class Influencer extends Party {
38
38
  @Prop({ required: false })
39
39
  financialManagementSheet?: string;
40
40
 
@@ -0,0 +1,29 @@
1
+ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2
+ import { HydratedDocument } from 'mongoose';
3
+
4
+ export type OrganizationDocument = HydratedDocument<Organization>;
5
+
6
+ @Schema({ timestamps: true, collection: 'organizations', strict: true })
7
+ export class Organization {
8
+ @Prop({ required: true, trim: true })
9
+ corporateName: string;
10
+
11
+ @Prop({ required: true, trim: true })
12
+ fantasyName: string;
13
+
14
+ @Prop({ required: true, unique: true, index: true })
15
+ cnpj: string;
16
+
17
+ @Prop()
18
+ logo?: string;
19
+
20
+ @Prop()
21
+ logoSmall?: string;
22
+
23
+ createdAt?: Date;
24
+ updatedAt?: Date;
25
+ }
26
+
27
+ export const OrganizationSchema = SchemaFactory.createForClass(Organization);
28
+
29
+ OrganizationSchema.index({ fantasyName: 'text', corporateName: 'text' });
@@ -0,0 +1,65 @@
1
+ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2
+ import { HydratedDocument, Schema as MongooseSchema, Types, model as MongooseModel } from 'mongoose';
3
+
4
+ export type PartyDocument = HydratedDocument<Party>;
5
+
6
+ @Schema({ _id: false })
7
+ export class Address {
8
+ @Prop() zipcode: string;
9
+ @Prop() city: string;
10
+ @Prop() state: string;
11
+ @Prop() street: string;
12
+ @Prop() number: string;
13
+ @Prop() complement: string;
14
+ }
15
+ export const AddressSchema = SchemaFactory.createForClass(Address);
16
+
17
+ @Schema({ _id: false })
18
+ export class Company {
19
+ @Prop() legalName: string;
20
+ @Prop() document: string;
21
+ @Prop() bank: string;
22
+ @Prop() agency: string;
23
+ @Prop() account: string;
24
+ @Prop() digit: string;
25
+ @Prop() pix: string;
26
+ @Prop() email: string;
27
+ @Prop({ required: false }) omieGrapaId?: string;
28
+ @Prop({ required: false }) omieOmaId?: string;
29
+ }
30
+ export const CompanySchema = SchemaFactory.createForClass(Company);
31
+
32
+ @Schema({ _id: false })
33
+ export class Individual {
34
+ @Prop() rg: string;
35
+ @Prop() cpf: string;
36
+ @Prop() birthday: Date;
37
+ @Prop() maritalStatus: string;
38
+ @Prop() nationality: string;
39
+ @Prop() profession: string;
40
+ }
41
+ export const IndividualSchema = SchemaFactory.createForClass(Individual);
42
+
43
+ @Schema({ timestamps: true })
44
+ export class Party {
45
+ @Prop({ type: MongooseSchema.Types.ObjectId, auto: true, required: false })
46
+ _id?: Types.ObjectId;
47
+
48
+ @Prop() name: string;
49
+ @Prop({ required: false }) email?: string;
50
+ @Prop({ required: false }) phone?: string;
51
+ @Prop({ required: false }) picture?: string;
52
+ @Prop({ type: AddressSchema, required: false }) address?: Address;
53
+ @Prop({ type: CompanySchema, required: false }) company?: Company;
54
+ @Prop({ type: IndividualSchema, required: false }) individual?: Individual;
55
+ @Prop({ default: Date.now, required: false }) createdAt?: Date;
56
+ @Prop({ default: Date.now, required: false }) updatedAt?: Date;
57
+ }
58
+ export const PartySchema = SchemaFactory.createForClass(Party);
59
+
60
+ PartySchema.index({ name: 1 });
61
+ PartySchema.index({ 'company.document': 1 });
62
+ PartySchema.index({ 'company.legalName': 1 });
63
+ PartySchema.index({ createdAt: -1 });
64
+
65
+ export const PartyModel = MongooseModel('Party', PartySchema);
@@ -1,11 +1,11 @@
1
1
  import { Schema, SchemaFactory } from '@nestjs/mongoose';
2
2
  import { HydratedDocument, model as MongooseModel } from 'mongoose';
3
- import { User } from './user.schema';
3
+ import { Party } from './party.schema';
4
4
 
5
5
  export type SupplierDocument = HydratedDocument<Supplier>;
6
6
 
7
7
  @Schema({ timestamps: true })
8
- export class Supplier extends User {}
8
+ export class Supplier extends Party {}
9
9
 
10
10
  export const SupplierSchema = SchemaFactory.createForClass(Supplier);
11
11
  export const SupplierModel = MongooseModel('Supplier', SupplierSchema);
@@ -0,0 +1,48 @@
1
+ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2
+ import { HydratedDocument, Types } from 'mongoose';
3
+
4
+ export type TriggerRecipientType = 'user' | 'group';
5
+
6
+ export class TriggerRecipient {
7
+ @Prop({ type: String, enum: ['user', 'group'], required: true })
8
+ type: TriggerRecipientType;
9
+
10
+ @Prop({ type: Types.ObjectId, required: true })
11
+ refId: Types.ObjectId;
12
+ }
13
+
14
+ export type TriggerDocument = HydratedDocument<Trigger>;
15
+
16
+ @Schema({ timestamps: true, collection: 'trigger' })
17
+ export class Trigger {
18
+ @Prop({ required: true, trim: true })
19
+ event: string;
20
+
21
+ @Prop({ type: Types.ObjectId, required: true, index: true })
22
+ organizationId: Types.ObjectId;
23
+
24
+ @Prop({ required: true, trim: true })
25
+ name: string;
26
+
27
+ @Prop({ default: true })
28
+ active: boolean;
29
+
30
+ @Prop({ required: true })
31
+ title: string;
32
+
33
+ @Prop({ required: true })
34
+ inAppBody: string;
35
+
36
+ @Prop({ required: true })
37
+ emailTemplate: string;
38
+
39
+ @Prop({ type: [TriggerRecipient], default: [] })
40
+ recipients: TriggerRecipient[];
41
+
42
+ createdAt?: Date;
43
+ updatedAt?: Date;
44
+ }
45
+
46
+ export const TriggerSchema = SchemaFactory.createForClass(Trigger);
47
+
48
+ TriggerSchema.index({ event: 1, organizationId: 1 }, { unique: true });