@grapadigital/shared-schemas 1.0.242 → 1.1.1

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.
Files changed (150) hide show
  1. package/dist/index.d.ts +42 -42
  2. package/dist/schemas/action.schema.d.ts +9 -34
  3. package/dist/schemas/action.schema.js +81 -64
  4. package/dist/schemas/assignment.schema.d.ts +3 -28
  5. package/dist/schemas/assignment.schema.js +44 -44
  6. package/dist/schemas/attachment.schema.d.ts +13 -0
  7. package/dist/schemas/attachment.schema.js +28 -0
  8. package/dist/schemas/benchmark.schema.d.ts +3 -28
  9. package/dist/schemas/benchmark.schema.js +11 -6
  10. package/dist/schemas/campaign.schema.d.ts +2 -27
  11. package/dist/schemas/campaign.schema.js +4 -4
  12. package/dist/schemas/client.schema.d.ts +18 -79
  13. package/dist/schemas/client.schema.js +73 -71
  14. package/dist/schemas/comment.schema.d.ts +5 -30
  15. package/dist/schemas/comment.schema.js +42 -37
  16. package/dist/schemas/commission.schema.d.ts +5 -30
  17. package/dist/schemas/commission.schema.js +10 -10
  18. package/dist/schemas/content-capture-process.schema.d.ts +6 -31
  19. package/dist/schemas/content-capture-process.schema.js +24 -17
  20. package/dist/schemas/content-draft.schema.d.ts +2 -27
  21. package/dist/schemas/content-draft.schema.js +5 -5
  22. package/dist/schemas/content.schema.d.ts +6 -31
  23. package/dist/schemas/content.schema.js +84 -74
  24. package/dist/schemas/contract.schema.d.ts +3 -28
  25. package/dist/schemas/contract.schema.js +5 -5
  26. package/dist/schemas/creative.schema.d.ts +6 -31
  27. package/dist/schemas/creative.schema.js +22 -31
  28. package/dist/schemas/export-comments-job.schema.d.ts +2 -27
  29. package/dist/schemas/export-comments-job.schema.js +6 -6
  30. package/dist/schemas/group.schema.d.ts +1 -26
  31. package/dist/schemas/group.schema.js +5 -5
  32. package/dist/schemas/influencer.schema.d.ts +6 -31
  33. package/dist/schemas/influencer.schema.js +16 -18
  34. package/dist/schemas/invoice.schema.d.ts +4 -29
  35. package/dist/schemas/invoice.schema.js +42 -32
  36. package/dist/schemas/job.schema.d.ts +2 -27
  37. package/dist/schemas/job.schema.js +14 -14
  38. package/dist/schemas/lead.schema.d.ts +1 -26
  39. package/dist/schemas/lead.schema.js +67 -64
  40. package/dist/schemas/log.schema.d.ts +1 -26
  41. package/dist/schemas/log.schema.js +24 -24
  42. package/dist/schemas/note.schema.d.ts +1 -26
  43. package/dist/schemas/note.schema.js +9 -9
  44. package/dist/schemas/notifications.schema.d.ts +1 -26
  45. package/dist/schemas/notifications.schema.js +8 -8
  46. package/dist/schemas/organization.schema.d.ts +2 -26
  47. package/dist/schemas/organization.schema.js +8 -4
  48. package/dist/schemas/party.schema.d.ts +1 -26
  49. package/dist/schemas/party.schema.js +11 -11
  50. package/dist/schemas/payment.schema.d.ts +12 -49
  51. package/dist/schemas/payment.schema.js +66 -69
  52. package/dist/schemas/profile.schema.d.ts +3 -28
  53. package/dist/schemas/profile.schema.js +6 -6
  54. package/dist/schemas/project.schema.d.ts +4 -29
  55. package/dist/schemas/project.schema.js +13 -13
  56. package/dist/schemas/prospect.schema.d.ts +3 -28
  57. package/dist/schemas/prospect.schema.js +9 -9
  58. package/dist/schemas/recruitment.schema.d.ts +5 -30
  59. package/dist/schemas/recruitment.schema.js +36 -36
  60. package/dist/schemas/responsible.schema.d.ts +0 -26
  61. package/dist/schemas/responsible.schema.js +6 -6
  62. package/dist/schemas/sale.schema.d.ts +31 -46
  63. package/dist/schemas/sale.schema.js +66 -62
  64. package/dist/schemas/script.schema.d.ts +6 -31
  65. package/dist/schemas/script.schema.js +21 -30
  66. package/dist/schemas/snapshot.schema.d.ts +3 -28
  67. package/dist/schemas/snapshot.schema.js +6 -6
  68. package/dist/schemas/store-visit.schema.d.ts +2 -27
  69. package/dist/schemas/store-visit.schema.js +21 -17
  70. package/dist/schemas/store.schema.d.ts +3 -28
  71. package/dist/schemas/store.schema.js +8 -8
  72. package/dist/schemas/supplier.schema.d.ts +2 -27
  73. package/dist/schemas/supplier.schema.js +3 -3
  74. package/dist/schemas/tag.schema.d.ts +1 -26
  75. package/dist/schemas/tag.schema.js +5 -5
  76. package/dist/schemas/task.schema.d.ts +9 -34
  77. package/dist/schemas/task.schema.js +67 -67
  78. package/dist/schemas/token.schema.d.ts +1 -26
  79. package/dist/schemas/token.schema.js +3 -3
  80. package/dist/schemas/trigger.schema.d.ts +2 -27
  81. package/dist/schemas/trigger.schema.js +5 -5
  82. package/dist/schemas/user.schema.d.ts +2 -27
  83. package/dist/schemas/user.schema.js +7 -7
  84. package/dist/schemas/webhook.schema.d.ts +1 -26
  85. package/dist/schemas/webhook.schema.js +10 -10
  86. package/dist/utils/merge-metrics-breakdown.util.d.ts +1 -1
  87. package/dist/utils/merge-metrics-breakdown.util.js +7 -2
  88. package/dist/utils/normalize-content-link.util.js +7 -7
  89. package/package.json +22 -10
  90. package/.eslintrc.json +0 -28
  91. package/.prettierrc +0 -4
  92. package/dist/schemas/profile-followers-snapshot.schema.d.ts +0 -67
  93. package/dist/schemas/profile-followers-snapshot.schema.js +0 -65
  94. package/dist/schemas/schedule.schema.d.ts +0 -73
  95. package/dist/schemas/schedule.schema.js +0 -116
  96. package/dist/utils/cost-per-impact.util.d.ts +0 -37
  97. package/dist/utils/cost-per-impact.util.js +0 -72
  98. package/dist/utils/influencer-contract.util.d.ts +0 -32
  99. package/dist/utils/influencer-contract.util.js +0 -77
  100. package/docs/code-review.md +0 -27
  101. package/docs/constitution.md +0 -75
  102. package/docs/specs/GD-692.md +0 -112
  103. package/docs/specs/GD-761.md +0 -94
  104. package/index.d.ts +0 -3
  105. package/src/index.ts +0 -42
  106. package/src/schemas/action.schema.ts +0 -328
  107. package/src/schemas/assignment.schema.ts +0 -154
  108. package/src/schemas/benchmark.schema.ts +0 -39
  109. package/src/schemas/campaign.schema.ts +0 -38
  110. package/src/schemas/client.schema.ts +0 -319
  111. package/src/schemas/comment.schema.ts +0 -216
  112. package/src/schemas/commission.schema.ts +0 -108
  113. package/src/schemas/content-capture-process.schema.ts +0 -195
  114. package/src/schemas/content-draft.schema.ts +0 -49
  115. package/src/schemas/content.schema.ts +0 -688
  116. package/src/schemas/contract.schema.ts +0 -44
  117. package/src/schemas/creative.schema.ts +0 -256
  118. package/src/schemas/export-comments-job.schema.ts +0 -59
  119. package/src/schemas/group.schema.ts +0 -23
  120. package/src/schemas/influencer.schema.ts +0 -184
  121. package/src/schemas/invoice.schema.ts +0 -164
  122. package/src/schemas/job.schema.ts +0 -111
  123. package/src/schemas/lead.schema.ts +0 -372
  124. package/src/schemas/log.schema.ts +0 -91
  125. package/src/schemas/note.schema.ts +0 -34
  126. package/src/schemas/notifications.schema.ts +0 -61
  127. package/src/schemas/organization.schema.ts +0 -29
  128. package/src/schemas/party.schema.ts +0 -65
  129. package/src/schemas/payment.schema.ts +0 -275
  130. package/src/schemas/profile.schema.ts +0 -77
  131. package/src/schemas/project.schema.ts +0 -116
  132. package/src/schemas/prospect.schema.ts +0 -62
  133. package/src/schemas/recruitment.schema.ts +0 -277
  134. package/src/schemas/responsible.schema.ts +0 -27
  135. package/src/schemas/sale.schema.ts +0 -297
  136. package/src/schemas/script.schema.ts +0 -235
  137. package/src/schemas/snapshot.schema.ts +0 -55
  138. package/src/schemas/store-visit.schema.ts +0 -68
  139. package/src/schemas/store.schema.ts +0 -52
  140. package/src/schemas/supplier.schema.ts +0 -12
  141. package/src/schemas/tag.schema.ts +0 -26
  142. package/src/schemas/task.schema.ts +0 -205
  143. package/src/schemas/token.schema.ts +0 -42
  144. package/src/schemas/trigger.schema.ts +0 -48
  145. package/src/schemas/user.schema.ts +0 -59
  146. package/src/schemas/webhook.schema.ts +0 -81
  147. package/src/utils/merge-metrics-breakdown.util.ts +0 -51
  148. package/src/utils/normalize-content-link.util.ts +0 -31
  149. package/tsconfig.build.json +0 -5
  150. package/tsconfig.json +0 -29
@@ -1,319 +0,0 @@
1
- import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2
- import { ApiProperty } from '@nestjs/swagger';
3
- import {
4
- HydratedDocument,
5
- model as MongooseModel,
6
- Schema as MongooseSchema,
7
- Types,
8
- } from 'mongoose';
9
- import { Party } from './party.schema';
10
- import { Profile } from './profile.schema';
11
- import { Responsible, ResponsibleSchema } from './responsible.schema';
12
-
13
- export type ClientDocument = HydratedDocument<Client>;
14
-
15
- /**
16
- * Personalizações de cliente: ligam telas e regras que valem só para ele.
17
- * Ver GD-683 (samsung) e GD-663 (shoulder).
18
- */
19
- export const CLIENT_CUSTOMIZATION_VALUES = ['samsung', 'shoulder'] as const;
20
- export type ClientCustomization = (typeof CLIENT_CUSTOMIZATION_VALUES)[number];
21
-
22
- /**
23
- * Catálogo de métricas que podem virar meta no Tier ou na Meta anual do
24
- * cliente. Quem cadastra escolhe a métrica e o valor; nada fica fixo.
25
- * `viralReachEngagementRate` é o limite de viral e só vale no Tier.
26
- * Ver GD-687.
27
- */
28
- export const CLIENT_GOAL_METRIC_VALUES = [
29
- 'potentialReach',
30
- 'reachCount',
31
- 'impressionCount',
32
- 'engagementCount',
33
- 'engagementRate',
34
- 'reachEngagementRate',
35
- 'followersEngagementRate',
36
- 'qualifiedEngagementRate',
37
- 'effectiveReach',
38
- 'earnedMediaValue',
39
- 'score',
40
- 'costPerInfluency',
41
- 'costPerImpact',
42
- 'costPerEngagement',
43
- 'savedCount',
44
- 'shareCount',
45
- 'videoCompletionRate',
46
- 'viralReachEngagementRate',
47
- ] as const;
48
- export type ClientGoalMetric = (typeof CLIENT_GOAL_METRIC_VALUES)[number];
49
-
50
- export type ClientGoalMetricUnit = 'count' | 'rate' | 'currency';
51
-
52
- /** Unidade de cada métrica. `rate` é guardado como fração (0,10 = 10%). */
53
- export const CLIENT_GOAL_METRIC_UNITS: Record<ClientGoalMetric, ClientGoalMetricUnit> = {
54
- potentialReach: 'count',
55
- reachCount: 'count',
56
- impressionCount: 'count',
57
- engagementCount: 'count',
58
- engagementRate: 'rate',
59
- reachEngagementRate: 'rate',
60
- followersEngagementRate: 'rate',
61
- qualifiedEngagementRate: 'rate',
62
- effectiveReach: 'count',
63
- earnedMediaValue: 'currency',
64
- score: 'count',
65
- costPerInfluency: 'currency',
66
- costPerImpact: 'currency',
67
- costPerEngagement: 'currency',
68
- savedCount: 'count',
69
- shareCount: 'count',
70
- videoCompletionRate: 'rate',
71
- viralReachEngagementRate: 'rate',
72
- };
73
-
74
- @Schema({ _id: false })
75
- export class Cluster {
76
- @Prop({ required: true })
77
- key: string;
78
-
79
- @Prop({ required: true })
80
- label: string;
81
- }
82
-
83
- export const ClusterSchema = SchemaFactory.createForClass(Cluster);
84
-
85
- /**
86
- * Squad do cliente (ex.: { key: 'alto_padrao', label: 'Alto Padrão' }). A chave
87
- * é gravada no Recrutamento (`scope.squad`) e no Contrato (`squad`); o label é
88
- * o texto da tela. Ver GD-770.
89
- */
90
- @Schema({ _id: false })
91
- export class ClientSquad {
92
- @Prop({ required: true })
93
- key: string;
94
-
95
- @Prop({ required: true })
96
- label: string;
97
- }
98
-
99
- export const ClientSquadSchema = SchemaFactory.createForClass(ClientSquad);
100
-
101
- @Schema({ _id: false })
102
- export class Company {
103
- @Prop()
104
- legalName: string;
105
-
106
- @Prop()
107
- document: string;
108
- }
109
-
110
- export const CompanySchema = SchemaFactory.createForClass(Company);
111
-
112
- @Schema({ _id: false })
113
- export class CommissionRange {
114
- @Prop({ required: false })
115
- startValue: number;
116
-
117
- @Prop({ required: false })
118
- endValue: number;
119
-
120
- @Prop({ required: true })
121
- percent: number;
122
- }
123
-
124
- export const CommissionRangeSchema = SchemaFactory.createForClass(CommissionRange);
125
-
126
- @Schema({ _id: false })
127
- export class ClientMetricGoal {
128
- @ApiProperty({ enum: CLIENT_GOAL_METRIC_VALUES, example: 'potentialReach' })
129
- @Prop({ type: String, enum: CLIENT_GOAL_METRIC_VALUES, required: true })
130
- metric: ClientGoalMetric;
131
-
132
- /** Na unidade da métrica (`CLIENT_GOAL_METRIC_UNITS`); `rate` em fração. */
133
- @ApiProperty({ example: 120000000, description: 'Na unidade da métrica; percentuais em fração (0,25 = 25%)' })
134
- @Prop({ type: Number, required: true })
135
- value: number;
136
- }
137
-
138
- export const ClientMetricGoalSchema = SchemaFactory.createForClass(ClientMetricGoal);
139
-
140
- /**
141
- * Faixa de seguidores do cliente com as metas dela (ex.: Micro, Macro, Hero,
142
- * Icon da Samsung). O Tier é do cliente, não do Influenciador: para mudar a
143
- * meta, edita o Tier. Faixas inclusivas nas duas pontas, contínuas e sem
144
- * sobreposição (validado na api-entities). Ver GD-687.
145
- */
146
- @Schema({ _id: false })
147
- export class ClientTier {
148
- @Prop({ type: String, required: true })
149
- name: string;
150
-
151
- @Prop({ type: Number, required: true })
152
- minFollowers: number;
153
-
154
- /** `null` = sem teto (só o último Tier). */
155
- @Prop({ type: Number, required: false, default: null })
156
- maxFollowers?: number | null;
157
-
158
- @Prop({ type: [ClientMetricGoalSchema], default: [] })
159
- goals: ClientMetricGoal[];
160
- }
161
-
162
- export const ClientTierSchema = SchemaFactory.createForClass(ClientTier);
163
-
164
- /** Metas do cliente num ano (alimentam os cards do gen_ia). Ver GD-687. */
165
- @Schema({ _id: false })
166
- export class ClientAnnualGoal {
167
- @Prop({ type: Number, required: true })
168
- year: number;
169
-
170
- @Prop({ type: [ClientMetricGoalSchema], default: [] })
171
- goals: ClientMetricGoal[];
172
- }
173
-
174
- export const ClientAnnualGoalSchema = SchemaFactory.createForClass(ClientAnnualGoal);
175
-
176
- @Schema({ _id: false })
177
- export class AgencyCommissionPeriod {
178
- @Prop({ type: [CommissionRangeSchema], required: true, default: [] })
179
- ranges: CommissionRange[];
180
-
181
- @Prop({ required: true })
182
- startDate: Date;
183
-
184
- @Prop({ required: true })
185
- endDate: Date;
186
- }
187
-
188
- export const AgencyCommissionPeriodSchema = SchemaFactory.createForClass(AgencyCommissionPeriod);
189
-
190
- @Schema({ _id: false })
191
- export class NicheItem {
192
- @Prop({ required: true })
193
- id: string;
194
-
195
- @Prop({ required: true })
196
- name: string;
197
-
198
- @Prop({ default: null })
199
- parentId?: string;
200
- }
201
-
202
- export const NicheItemSchema = SchemaFactory.createForClass(NicheItem);
203
-
204
- /**
205
- * Responsáveis do cliente: `report` são usuários da plataforma que cuidam dos
206
- * relatórios; `brand` é o contato do lado da marca (texto livre, não é usuário).
207
- */
208
- @Schema({ _id: false })
209
- export class ClientResponsible {
210
- @ApiProperty({ type: () => [Responsible], required: false })
211
- @Prop({ type: [ResponsibleSchema], required: false, default: [] })
212
- report?: Responsible[];
213
-
214
- @ApiProperty({ example: 'Maite', required: false })
215
- @Prop({ type: String, required: false })
216
- brand?: string;
217
- }
218
-
219
- export const ClientResponsibleSchema = SchemaFactory.createForClass(ClientResponsible);
220
-
221
- @Schema({ timestamps: true })
222
- export class Client extends Party {
223
- @Prop({ type: [ClusterSchema], default: [] })
224
- clusters: Cluster[];
225
-
226
- @Prop({ type: [CompanySchema], default: [] })
227
- companies: Company[];
228
-
229
- @Prop({ type: String })
230
- type: string;
231
-
232
- @Prop({ type: String, enum: ['fixed', 'punctual'], required: false })
233
- engagement?: 'fixed' | 'punctual';
234
-
235
- @Prop({ type: [String], default: [] })
236
- categories: string[];
237
-
238
- @Prop({
239
- type: [NicheItemSchema],
240
- default: [],
241
- _id: false, required: false
242
- })
243
- niches?: NicheItem[];
244
-
245
- @Prop({ required: true, default: false })
246
- hasAgencyCommission: boolean;
247
-
248
- @Prop({ type: [AgencyCommissionPeriodSchema], default: [] })
249
- agencyCommission: AgencyCommissionPeriod[];
250
-
251
- /**
252
- * Times obrigatórios pra aprovação de Roteiro/Conteúdo (ex.: Samsung
253
- * exige Influência+Marcom+Produto). Vazio = 1 aprovação de qualquer
254
- * time já resolve (padrão da maioria dos clientes). Ver GD-532/GD-535.
255
- */
256
- @Prop({ type: [String], default: [] })
257
- requiredTeams: string[];
258
-
259
- /**
260
- * Análise GenIA: captura de comentários, classificação por IA e tudo que
261
- * depende deles (spam, taxa de engajamento qualificado, score, CPMI). Sem
262
- * isso, os conteúdos do cliente só recebem as métricas base da Primetag.
263
- * Também define quais clientes aparecem no hub de relatórios GenIA.
264
- * (Antigo `hasReport`.)
265
- */
266
- @Prop({ type: Boolean, default: false })
267
- hasGenIAAnalysis: boolean;
268
-
269
- /**
270
- * Personalização do cliente (ex.: `samsung`): liga as telas e regras
271
- * específicas dele no Flow e no Hub. Ausente ou `null` = comportamento
272
- * padrão. Nunca comparar id de cliente no código, sempre este campo.
273
- * Ver GD-683.
274
- */
275
- @Prop({ type: String, enum: CLIENT_CUSTOMIZATION_VALUES, required: false, default: null })
276
- customization?: ClientCustomization | null;
277
-
278
- /** Tiers do cliente (só com Personalização Samsung por enquanto). Ver GD-687. */
279
- @Prop({ type: [ClientTierSchema], default: [] })
280
- tiers: ClientTier[];
281
-
282
- /** Metas anuais do cliente (só com Personalização Samsung por enquanto). Ver GD-687. */
283
- @Prop({ type: [ClientAnnualGoalSchema], default: [] })
284
- annualGoals: ClientAnnualGoal[];
285
-
286
- /** Squads do cliente, para qualquer cliente. Ver `ClientSquad` e GD-770. */
287
- @Prop({ type: [ClientSquadSchema], default: [] })
288
- squads: ClientSquad[];
289
-
290
- /**
291
- * Client de organização (ex.: "Oma Creators"): representa a organização
292
- * inteira, não uma marca. No hub, mostra todas as actions dessa organização
293
- * independentemente do client (marca) de cada action. Não liga a análise
294
- * GenIA das actions — isso é `Client.hasGenIAAnalysis` do client da action
295
- * ou `Action.hasGenIAAnalysis`.
296
- */
297
- @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Organization', required: false })
298
- organization?: Types.ObjectId;
299
-
300
- @Prop({ type: ClientResponsibleSchema, required: false })
301
- responsible?: ClientResponsible;
302
-
303
- // Perfis da marca nas redes sociais (mesmo vínculo de Influencer.profiles).
304
- // Usado pelo comment-capture-worker pra reconhecer comentário da própria marca.
305
- @Prop([
306
- { type: MongooseSchema.Types.ObjectId, ref: 'Profile', required: false },
307
- ])
308
- profiles?: Types.ObjectId[] | Profile[];
309
- }
310
-
311
- export const ClientSchema = SchemaFactory.createForClass(Client);
312
-
313
- ClientSchema.index({ name: 1 });
314
- ClientSchema.index({ 'company.legalName': 1 });
315
- ClientSchema.index({ 'company.document': 1 });
316
- ClientSchema.index({ createdAt: -1 });
317
- ClientSchema.index({ organization: 1 }, { sparse: true });
318
-
319
- export const ClientModel = MongooseModel('Client', ClientSchema);
@@ -1,216 +0,0 @@
1
- import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2
- import {
3
- HydratedDocument,
4
- Schema as MongooseSchema,
5
- Types,
6
- model as MongooseModel,
7
- } from 'mongoose';
8
- import { Content } from './content.schema';
9
- import { Action } from './action.schema';
10
-
11
- export type CommentDocument = HydratedDocument<Comment>;
12
-
13
- export const COMMENT_TARGET_VALUES = ['brand', 'influencer', 'content', 'emoji', 'spam'] as const;
14
- export type CommentTarget = (typeof COMMENT_TARGET_VALUES)[number];
15
-
16
- export const COMMENT_SUBJECT_VALUES = [
17
- 'compliment_to_person',
18
- 'criticism',
19
- 'question',
20
- 'brand_recognition',
21
- 'influencer_response',
22
- 'account',
23
- 'reaction',
24
- 'doubt',
25
- 'about_story',
26
- 'about_self',
27
- 'competition',
28
- 'customer_service',
29
- 'tagged_someone',
30
- 'other',
31
- 'emoji_reaction',
32
- ] as const;
33
- export type CommentSubject = (typeof COMMENT_SUBJECT_VALUES)[number];
34
-
35
- export const COMMENT_CLASSIFICATION_STATUS_VALUES = [
36
- 'pending',
37
- 'processing',
38
- 'completed',
39
- 'failed',
40
- 'not_applicable',
41
- ] as const;
42
- export type CommentClassificationStatus = (typeof COMMENT_CLASSIFICATION_STATUS_VALUES)[number];
43
-
44
- export const COMMENT_SPAM_RULE_VALUES = ['duplicate_text', 'repeat_author', 'manual', 'unknown'] as const;
45
- export type CommentSpamRule = (typeof COMMENT_SPAM_RULE_VALUES)[number];
46
-
47
- // Por que o comentário foi marcado como spam. `groupKey` identifica os outros
48
- // comentários do mesmo conteúdo que caíram na mesma regra: autor normalizado
49
- // (repeat_author) ou `autor::texto` normalizado (duplicate_text).
50
- @Schema({ _id: false })
51
- export class CommentSpamReason {
52
- @Prop({ type: String, enum: COMMENT_SPAM_RULE_VALUES, required: true })
53
- rule: CommentSpamRule;
54
-
55
- @Prop({ type: Number, required: false })
56
- threshold?: number;
57
-
58
- @Prop({ type: Number, required: false })
59
- matchCount?: number;
60
-
61
- @Prop({ type: String, required: false })
62
- groupKey?: string;
63
- }
64
-
65
- export const CommentSpamReasonSchema = SchemaFactory.createForClass(CommentSpamReason);
66
-
67
- @Schema({ _id: false })
68
- export class CommentClassifiedBy {
69
- @Prop({ type: String, required: false })
70
- team?: string;
71
-
72
- @Prop({ type: String, required: false })
73
- name?: string;
74
-
75
- @Prop({ type: String, required: false })
76
- email?: string;
77
- }
78
-
79
- export const CommentClassifiedBySchema = SchemaFactory.createForClass(CommentClassifiedBy);
80
-
81
- @Schema({ timestamps: true })
82
- export class Comment {
83
- @Prop({ type: MongooseSchema.Types.ObjectId, auto: true, required: false })
84
- _id?: Types.ObjectId;
85
-
86
- @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Content', required: true })
87
- content: Types.ObjectId | Content;
88
-
89
- @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Action', required: true })
90
- action: Types.ObjectId | Action;
91
-
92
- @Prop({ type: String, required: true })
93
- externalId: string;
94
-
95
- @Prop({ type: String, required: true })
96
- author: string;
97
-
98
- @Prop({ type: String, required: false, default: null })
99
- authorProfileUrl?: string | null;
100
-
101
- @Prop({ type: String, required: false, default: null })
102
- authorThumbnailUrl?: string | null;
103
-
104
- @Prop({ type: String, required: true })
105
- text: string;
106
-
107
- @Prop({ type: String, required: false, default: null })
108
- url?: string | null;
109
-
110
- @Prop({ type: Date, required: true })
111
- postedAt: Date;
112
-
113
- @Prop({ type: Number, required: false, default: 0 })
114
- likeCount?: number;
115
-
116
- @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Comment', required: false, default: null })
117
- parent?: Types.ObjectId | Comment | null;
118
-
119
- @Prop({
120
- type: String,
121
- enum: COMMENT_TARGET_VALUES,
122
- required: false,
123
- default: null,
124
- })
125
- target?: CommentTarget | null;
126
-
127
- @Prop({
128
- type: String,
129
- enum: COMMENT_SUBJECT_VALUES,
130
- required: false,
131
- default: null,
132
- })
133
- subject?: CommentSubject | null;
134
-
135
- @Prop({
136
- type: String,
137
- enum: ['positive', 'negative', 'neutral'],
138
- required: false,
139
- default: null,
140
- })
141
- polarity?: 'positive' | 'negative' | 'neutral' | null;
142
-
143
- @Prop({
144
- type: String,
145
- enum: ['awareness', 'consideration', 'conversion', 'none'],
146
- required: false,
147
- default: null,
148
- })
149
- funnel?: 'awareness' | 'consideration' | 'conversion' | 'none' | null;
150
-
151
- @Prop({ type: Boolean, required: false, default: false })
152
- isEmojiOnly?: boolean;
153
-
154
- @Prop({ type: Boolean, required: false, default: false })
155
- isSpam?: boolean;
156
-
157
- @Prop({ type: CommentSpamReasonSchema, required: false, default: null })
158
- spamReason?: CommentSpamReason | null;
159
-
160
- // Tirado do spam manualmente: as regras automáticas de spam ignoram esse
161
- // comentário (e ele sai da contagem do grupo), mas a IA continua classificando.
162
- @Prop({ type: Boolean, required: false, default: false })
163
- spamOverride?: boolean;
164
-
165
- // Classificação ajustada manualmente: nenhum worker sobrescreve
166
- // target/subject/polarity/funnel/isSpam desse comentário.
167
- @Prop({ type: Boolean, required: false, default: false })
168
- isManuallyClassified?: boolean;
169
-
170
- @Prop({ type: Date, required: false, default: null })
171
- manuallyClassifiedAt?: Date | null;
172
-
173
- @Prop({ type: CommentClassifiedBySchema, required: false, default: null })
174
- manuallyClassifiedBy?: CommentClassifiedBy | null;
175
-
176
- @Prop({
177
- type: String,
178
- enum: COMMENT_CLASSIFICATION_STATUS_VALUES,
179
- required: false,
180
- default: 'pending',
181
- })
182
- classificationStatus?: CommentClassificationStatus;
183
-
184
- @Prop({ type: String, required: false, default: null })
185
- classificationError?: string | null;
186
-
187
- @Prop({ type: Date, required: false, default: null })
188
- classificationProcessedAt?: Date | null;
189
-
190
- @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Comment', required: false, default: null })
191
- sourceCommentId?: Types.ObjectId | Comment | null;
192
-
193
- @Prop({ default: Date.now, required: false })
194
- createdAt?: Date;
195
-
196
- @Prop({ default: Date.now, required: false })
197
- updatedAt?: Date;
198
- }
199
-
200
- export const CommentSchema = SchemaFactory.createForClass(Comment);
201
-
202
- // partialFilterExpression não aceita $exists:false (só $exists:true) — usamos
203
- // igualdade com null, que no Mongo casa tanto "campo ausente" quanto "campo
204
- // null" (cobre o documento original, sem exigir que quem insere via
205
- // bulkWrite raw declare sourceCommentId explicitamente).
206
- CommentSchema.index(
207
- { content: 1, externalId: 1 },
208
- { unique: true, partialFilterExpression: { sourceCommentId: null } },
209
- );
210
- CommentSchema.index({ action: 1, funnel: 1 });
211
- CommentSchema.index({ action: 1, target: 1 });
212
- CommentSchema.index({ content: 1, parent: 1 });
213
- CommentSchema.index({ content: 1, classificationStatus: 1 });
214
- CommentSchema.index({ content: 1, 'spamReason.groupKey': 1 });
215
-
216
- export const CommentModel = MongooseModel('Comment', CommentSchema);
@@ -1,108 +0,0 @@
1
- import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2
-
3
- import {
4
- HydratedDocument,
5
- Schema as MongooseSchema,
6
- Types,
7
- model as MongooseModel,
8
- } from 'mongoose';
9
-
10
- import { Sale } from './sale.schema';
11
-
12
- export type CommissionDocument = HydratedDocument<Commission>;
13
-
14
- @Schema({ timestamps: true })
15
- export class Commission {
16
- @Prop({ type: MongooseSchema.Types.ObjectId, auto: true, required: false })
17
- _id?: Types.ObjectId;
18
-
19
- @Prop({ type: String, required: true })
20
- title: string;
21
-
22
- @Prop({ type: Number, required: true })
23
- installmentNumber: number;
24
-
25
- @Prop({ type: String, required: true })
26
- email: string;
27
-
28
- @Prop({
29
- type: String,
30
- enum: ['origination', 'commercial', 'planning', 'curation'],
31
- default: 'origination',
32
- required: true,
33
- })
34
- role: 'origination' | 'commercial' | 'planning' | 'curation';
35
-
36
- @Prop({ type: Number, required: true })
37
- value: number;
38
-
39
- @Prop({ type: Number, required: true, min: 0, max: 100 })
40
- percentage: number;
41
-
42
- @Prop({
43
- type: String,
44
- enum: ['pending', 'approved', 'ready', 'received', 'paid', 'cancelled', 'disputed', 'reproved'],
45
- default: 'pending',
46
- required: true,
47
- })
48
- status: 'pending' | 'approved' | 'ready' | 'received' | 'paid' | 'cancelled' | 'disputed' | 'reproved';
49
-
50
- @Prop({
51
- type: String,
52
- enum: ['collaborator', 'agency', 'bonus'],
53
- required: true,
54
- })
55
- type: 'collaborator' | 'agency' | 'bonus';
56
-
57
- @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Sale', required: false })
58
- sale: Types.ObjectId | Sale;
59
-
60
- @Prop({ type: Date, required: false })
61
- paidAt?: Date;
62
-
63
- @Prop({ type: Date, required: false })
64
- approvedAt?: Date;
65
-
66
- @Prop({ type: Date, required: false })
67
- readyAt?: Date;
68
-
69
- @Prop({ type: Date, required: false })
70
- receivedAt?: Date;
71
-
72
- @Prop({ type: Date, required: false })
73
- paymentDate?: Date;
74
-
75
- @Prop({ type: Object, required: false })
76
- approvedBy?: { _id: string; name: string; email: string; username: string };
77
-
78
- @Prop({ type: Object, required: false })
79
- reprovedBy?: { _id: string; name: string; email: string; username: string };
80
-
81
- @Prop({ type: String, required: false })
82
- description?: string;
83
-
84
- @Prop({ type: String, required: false })
85
- reason?: string;
86
-
87
- @Prop({ type: Date, default: Date.now, required: false })
88
- createdAt?: Date;
89
-
90
- @Prop({ type: Date, default: Date.now, required: false })
91
- updatedAt?: Date;
92
-
93
- @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
94
- organization: Types.ObjectId;
95
-
96
- @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Payment', required: false })
97
- payment?: Types.ObjectId;
98
- }
99
-
100
- export const CommissionSchema = SchemaFactory.createForClass(Commission);
101
-
102
- CommissionSchema.index({ email: 1, organization: 1 });
103
- CommissionSchema.index({ email: 1, status: 1 });
104
- CommissionSchema.index({ email: 1, createdAt: -1 });
105
- CommissionSchema.index({ organization: 1, status: 1 });
106
- CommissionSchema.index({ sale: 1, installmentNumber: 1, status: 1 });
107
-
108
- export const CommissionModel = MongooseModel('Commission', CommissionSchema);