@grapadigital/shared-schemas 1.0.235 → 1.0.237

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.
@@ -106,8 +106,6 @@ export declare class Metrics {
106
106
  * manda; `tapBackCount` é o "voltar o story". Peso 1 no Real E/R. 2026-10-24.
107
107
  */
108
108
  stickerTapCount?: number | null;
109
- /** Reposts do post (Primetag `private_metrics.reposts`, perfil conectado). 2026-10-24. */
110
- repostCount?: number | null;
111
109
  replyCount?: number | null;
112
110
  tapForwardCount?: number | null;
113
111
  swipeForwardCount?: number | null;
@@ -147,10 +147,6 @@ __decorate([
147
147
  (0, mongoose_1.Prop)({ type: Number, required: false, default: null }),
148
148
  __metadata("design:type", Object)
149
149
  ], Metrics.prototype, "stickerTapCount", void 0);
150
- __decorate([
151
- (0, mongoose_1.Prop)({ type: Number, required: false, default: null }),
152
- __metadata("design:type", Object)
153
- ], Metrics.prototype, "repostCount", void 0);
154
150
  __decorate([
155
151
  (0, mongoose_1.Prop)({ type: Number, required: false, default: null }),
156
152
  __metadata("design:type", Object)
@@ -30,6 +30,8 @@ export declare const LEAD_PRESENTATION_FORMAT_VALUES: readonly ["online", "in_pe
30
30
  export type LeadPresentationFormat = (typeof LEAD_PRESENTATION_FORMAT_VALUES)[number];
31
31
  export declare const LEAD_PAYMENT_TERM_VALUES: readonly [30, 60, 90, 120];
32
32
  export type LeadPaymentTerm = (typeof LEAD_PAYMENT_TERM_VALUES)[number];
33
+ export declare const LEAD_BILLING_MODEL_VALUES: readonly ["transfer", "double_taxation", "direct_payment"];
34
+ export type LeadBillingModel = (typeof LEAD_BILLING_MODEL_VALUES)[number];
33
35
  export declare const LEAD_DELIVERABLE_VALUES: readonly ["content_strategy", "ppt_presentation", "curation_sheet", "production_sheet"];
34
36
  export type LeadDeliverable = (typeof LEAD_DELIVERABLE_VALUES)[number];
35
37
  export declare const LEAD_GOAL_VALUES: readonly ["awareness", "consideration", "intent"];
@@ -81,6 +83,7 @@ export declare class LeadBudget {
81
83
  totalBudget?: number;
82
84
  creatorsBudget?: number;
83
85
  paymentTerm?: LeadPaymentTerm;
86
+ billingModel?: LeadBillingModel;
84
87
  campaignDurationMonths?: number;
85
88
  }
86
89
  export declare const LeadBudgetSchema: import("mongoose").Schema<LeadBudget, import("mongoose").Model<LeadBudget, any, any, any, import("mongoose").Document<unknown, any, LeadBudget, any, {}> & LeadBudget & {
@@ -242,6 +245,12 @@ export declare class Lead {
242
245
  organization: Types.ObjectId;
243
246
  submittedAt?: Date;
244
247
  lastEditedAt?: Date;
248
+ /**
249
+ * Data de exclusão lógica (soft delete).
250
+ * Mantém o registro no banco de dados para fins de auditoria/histórico,
251
+ * mas deve ser desconsiderado nas consultas padrão (`deletedAt: null`).
252
+ */
253
+ deletedAt?: Date;
245
254
  general: LeadGeneral;
246
255
  confidentiality: LeadConfidentiality;
247
256
  budget: LeadBudget;
@@ -9,7 +9,7 @@ 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.LeadModel = exports.LeadSchema = exports.Lead = exports.LeadContentGuidelinesSchema = exports.LeadContentGuidelines = exports.LeadLogisticsSchema = exports.LeadLogistics = exports.LeadCurationSchema = exports.LeadCuration = exports.LeadAudienceSchema = exports.LeadAudience = exports.LeadDeliveryScopeSchema = exports.LeadDeliveryScope = exports.LeadObjectivesSchema = exports.LeadObjectives = exports.LeadStrategicContextSchema = exports.LeadStrategicContext = exports.LeadDeliverablesSchema = exports.LeadDeliverables = exports.LeadCompetitionSchema = exports.LeadCompetition = exports.LeadBudgetSchema = exports.LeadBudget = exports.LeadConfidentialitySchema = exports.LeadConfidentiality = exports.LeadGeneralSchema = exports.LeadGeneral = exports.LEAD_SECTION_KEYS = exports.LEAD_FOLLOWER_TIER_VALUES = exports.LEAD_RIGHT_VALUES = exports.LEAD_CHANNEL_VALUES = exports.LEAD_GOAL_VALUES = exports.LEAD_DELIVERABLE_VALUES = exports.LEAD_PAYMENT_TERM_VALUES = exports.LEAD_PRESENTATION_FORMAT_VALUES = exports.LEAD_STATUS_VALUES = void 0;
12
+ exports.LeadModel = exports.LeadSchema = exports.Lead = exports.LeadContentGuidelinesSchema = exports.LeadContentGuidelines = exports.LeadLogisticsSchema = exports.LeadLogistics = exports.LeadCurationSchema = exports.LeadCuration = exports.LeadAudienceSchema = exports.LeadAudience = exports.LeadDeliveryScopeSchema = exports.LeadDeliveryScope = exports.LeadObjectivesSchema = exports.LeadObjectives = exports.LeadStrategicContextSchema = exports.LeadStrategicContext = exports.LeadDeliverablesSchema = exports.LeadDeliverables = exports.LeadCompetitionSchema = exports.LeadCompetition = exports.LeadBudgetSchema = exports.LeadBudget = exports.LeadConfidentialitySchema = exports.LeadConfidentiality = exports.LeadGeneralSchema = exports.LeadGeneral = exports.LEAD_SECTION_KEYS = exports.LEAD_FOLLOWER_TIER_VALUES = exports.LEAD_RIGHT_VALUES = exports.LEAD_CHANNEL_VALUES = exports.LEAD_GOAL_VALUES = exports.LEAD_DELIVERABLE_VALUES = exports.LEAD_BILLING_MODEL_VALUES = exports.LEAD_PAYMENT_TERM_VALUES = exports.LEAD_PRESENTATION_FORMAT_VALUES = exports.LEAD_STATUS_VALUES = void 0;
13
13
  const mongoose_1 = require("@nestjs/mongoose");
14
14
  const mongoose_2 = require("mongoose");
15
15
  // Lead = briefing de campanha preenchido pelo cliente numa página pública (GD-616).
@@ -17,6 +17,11 @@ const mongoose_2 = require("mongoose");
17
17
  exports.LEAD_STATUS_VALUES = ['draft', 'submitted'];
18
18
  exports.LEAD_PRESENTATION_FORMAT_VALUES = ['online', 'in_person', 'email_only'];
19
19
  exports.LEAD_PAYMENT_TERM_VALUES = [30, 60, 90, 120];
20
+ exports.LEAD_BILLING_MODEL_VALUES = [
21
+ 'transfer',
22
+ 'double_taxation',
23
+ 'direct_payment',
24
+ ];
20
25
  exports.LEAD_DELIVERABLE_VALUES = [
21
26
  'content_strategy',
22
27
  'ppt_presentation',
@@ -130,6 +135,10 @@ __decorate([
130
135
  (0, mongoose_1.Prop)({ type: Number, enum: exports.LEAD_PAYMENT_TERM_VALUES }),
131
136
  __metadata("design:type", Number)
132
137
  ], LeadBudget.prototype, "paymentTerm", void 0);
138
+ __decorate([
139
+ (0, mongoose_1.Prop)({ type: String, enum: exports.LEAD_BILLING_MODEL_VALUES }),
140
+ __metadata("design:type", String)
141
+ ], LeadBudget.prototype, "billingModel", void 0);
133
142
  __decorate([
134
143
  (0, mongoose_1.Prop)(),
135
144
  __metadata("design:type", Number)
@@ -400,6 +409,10 @@ __decorate([
400
409
  (0, mongoose_1.Prop)({ index: true }),
401
410
  __metadata("design:type", Date)
402
411
  ], Lead.prototype, "lastEditedAt", void 0);
412
+ __decorate([
413
+ (0, mongoose_1.Prop)({ index: true }),
414
+ __metadata("design:type", Date)
415
+ ], Lead.prototype, "deletedAt", void 0);
403
416
  __decorate([
404
417
  (0, mongoose_1.Prop)({ type: exports.LeadGeneralSchema, default: {} }),
405
418
  __metadata("design:type", LeadGeneral)
@@ -25,16 +25,25 @@
25
25
  /// <reference types="mongoose/types/inferrawdoctype" />
26
26
  import { HydratedDocument, Schema as MongooseSchema, Types } from 'mongoose';
27
27
  export type LogDocument = HydratedDocument<Log>;
28
+ export declare const LOG_REFERENCE_VALUES: readonly ["action", "recruitment", "content", "contract", "sale", "invoice", "payment", "assignment", "commission", "hub-access"];
29
+ export type LogReference = (typeof LOG_REFERENCE_VALUES)[number];
30
+ export declare const LOG_TYPE_VALUES: readonly ["created", "updated", "deleted", "email", "client-selected", "access-blocked"];
31
+ export type LogType = (typeof LOG_TYPE_VALUES)[number];
28
32
  declare class UpdatedBy {
29
33
  team: string;
30
34
  name: string;
31
35
  email: string;
32
36
  }
37
+ export declare class LogTarget {
38
+ /** uid da conta no Firebase do Hub (projeto hub-grapa). */
39
+ uid: string;
40
+ email: string;
41
+ }
33
42
  export declare class Log {
34
43
  _id?: Types.ObjectId;
35
44
  referenceId: string;
36
- reference: 'action' | 'recruitment' | 'content' | 'contract' | 'sale' | 'invoice' | 'payment' | 'assignment' | 'commission';
37
- type: 'created' | 'updated' | 'deleted' | 'email';
45
+ reference: LogReference;
46
+ type: LogType;
38
47
  phase?: string;
39
48
  changes: Record<string, {
40
49
  before: any;
@@ -42,6 +51,10 @@ export declare class Log {
42
51
  }>;
43
52
  updatedAt: Date;
44
53
  updatedBy?: UpdatedBy;
54
+ /**
55
+ * Conta do Hub afetada pela ação. Vazio fora de `hub-access`. Ver GD-760.
56
+ */
57
+ target?: LogTarget | null;
45
58
  }
46
59
  export declare const LogSchema: MongooseSchema<Log, import("mongoose").Model<Log, any, any, any, import("mongoose").Document<unknown, any, Log, any, {}> & Log & Required<{
47
60
  _id: Types.ObjectId;
@@ -9,9 +9,30 @@ 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.LogModel = exports.LogSchema = exports.Log = void 0;
12
+ exports.LogModel = exports.LogSchema = exports.Log = exports.LogTarget = exports.LOG_TYPE_VALUES = exports.LOG_REFERENCE_VALUES = void 0;
13
13
  const mongoose_1 = require("@nestjs/mongoose");
14
+ const swagger_1 = require("@nestjs/swagger");
14
15
  const mongoose_2 = require("mongoose");
16
+ exports.LOG_REFERENCE_VALUES = [
17
+ 'action',
18
+ 'recruitment',
19
+ 'content',
20
+ 'contract',
21
+ 'sale',
22
+ 'invoice',
23
+ 'payment',
24
+ 'assignment',
25
+ 'commission',
26
+ 'hub-access',
27
+ ];
28
+ exports.LOG_TYPE_VALUES = [
29
+ 'created',
30
+ 'updated',
31
+ 'deleted',
32
+ 'email',
33
+ 'client-selected',
34
+ 'access-blocked',
35
+ ];
15
36
  let UpdatedBy = class UpdatedBy {
16
37
  };
17
38
  __decorate([
@@ -29,6 +50,22 @@ __decorate([
29
50
  UpdatedBy = __decorate([
30
51
  (0, mongoose_1.Schema)({ _id: false })
31
52
  ], UpdatedBy);
53
+ let LogTarget = class LogTarget {
54
+ };
55
+ __decorate([
56
+ (0, swagger_1.ApiProperty)({ example: 'FmWcCgBLTwOR2YIEZ5toRdoRpGC3' }),
57
+ (0, mongoose_1.Prop)({ required: true }),
58
+ __metadata("design:type", String)
59
+ ], LogTarget.prototype, "uid", void 0);
60
+ __decorate([
61
+ (0, swagger_1.ApiProperty)({ example: 'pessoa@cliente.com.br' }),
62
+ (0, mongoose_1.Prop)({ required: true }),
63
+ __metadata("design:type", String)
64
+ ], LogTarget.prototype, "email", void 0);
65
+ LogTarget = __decorate([
66
+ (0, mongoose_1.Schema)({ _id: false })
67
+ ], LogTarget);
68
+ exports.LogTarget = LogTarget;
32
69
  let Log = class Log {
33
70
  };
34
71
  __decorate([
@@ -40,32 +77,13 @@ __decorate([
40
77
  __metadata("design:type", String)
41
78
  ], Log.prototype, "referenceId", void 0);
42
79
  __decorate([
43
- (0, mongoose_1.Prop)({
44
- required: true,
45
- enum: [
46
- 'action',
47
- 'recruitment',
48
- 'content',
49
- 'contract',
50
- 'sale',
51
- 'invoice',
52
- 'payment',
53
- 'assignment',
54
- 'commission',
55
- ],
56
- }),
80
+ (0, swagger_1.ApiProperty)({ enum: exports.LOG_REFERENCE_VALUES }),
81
+ (0, mongoose_1.Prop)({ required: true, enum: exports.LOG_REFERENCE_VALUES }),
57
82
  __metadata("design:type", String)
58
83
  ], Log.prototype, "reference", void 0);
59
84
  __decorate([
60
- (0, mongoose_1.Prop)({
61
- required: true,
62
- enum: [
63
- 'created',
64
- 'updated',
65
- 'deleted',
66
- 'email'
67
- ],
68
- }),
85
+ (0, swagger_1.ApiProperty)({ enum: exports.LOG_TYPE_VALUES }),
86
+ (0, mongoose_1.Prop)({ required: true, enum: exports.LOG_TYPE_VALUES }),
69
87
  __metadata("design:type", String)
70
88
  ], Log.prototype, "type", void 0);
71
89
  __decorate([
@@ -84,6 +102,11 @@ __decorate([
84
102
  (0, mongoose_1.Prop)({ type: UpdatedBy }),
85
103
  __metadata("design:type", UpdatedBy)
86
104
  ], Log.prototype, "updatedBy", void 0);
105
+ __decorate([
106
+ (0, swagger_1.ApiProperty)({ type: LogTarget, required: false, nullable: true }),
107
+ (0, mongoose_1.Prop)({ type: LogTarget, default: null }),
108
+ __metadata("design:type", Object)
109
+ ], Log.prototype, "target", void 0);
87
110
  Log = __decorate([
88
111
  (0, mongoose_1.Schema)()
89
112
  ], Log);
@@ -91,4 +114,5 @@ exports.Log = Log;
91
114
  exports.LogSchema = mongoose_1.SchemaFactory.createForClass(Log);
92
115
  exports.LogSchema.index({ referenceId: 1, reference: 1 });
93
116
  exports.LogSchema.index({ reference: 1, updatedAt: -1 });
117
+ exports.LogSchema.index({ reference: 1, 'target.uid': 1, updatedAt: -1 });
94
118
  exports.LogModel = (0, mongoose_2.model)('Log', exports.LogSchema);
@@ -0,0 +1,94 @@
1
+ # Spec: log: acesso ao Hub e troca de cliente
2
+
3
+ **Feature:** GD-761 (Story GD-760)
4
+ **Consumido por:** api-entities (GD-762)
5
+
6
+ ---
7
+
8
+ ## Descrição
9
+
10
+ O Log passa a guardar três coisas novas do Hub de Relatórios:
11
+
12
+ - alteração de acesso (criar, editar, remover), feita pela tela do Cliente no web-entities;
13
+ - troca de cliente (`POST /auth/select-client`);
14
+ - acesso bloqueado (conta de fora da Grapa com role diferente de `client`).
15
+
16
+ Hoje o Log só sabe quem fez (`updatedBy`). Aqui ele precisa saber também **quem foi afetado**, que é uma conta do Firebase do Hub e não um documento do Mongo. Isso vira o campo `target`.
17
+
18
+ `referenceId` continua sendo ObjectId e recebe o `clientId` do Cliente envolvido.
19
+
20
+ Os campos novos são opcionais e têm default `null`. Logs que já existem não mudam.
21
+
22
+ ## Schema
23
+
24
+ ### `log.schema.ts`
25
+
26
+ ```ts
27
+ export const LOG_REFERENCE_VALUES = [
28
+ 'action', 'recruitment', 'content', 'contract', 'sale',
29
+ 'invoice', 'payment', 'assignment', 'commission',
30
+ 'hub-access', // novo
31
+ ] as const;
32
+ export type LogReference = (typeof LOG_REFERENCE_VALUES)[number];
33
+
34
+ export const LOG_TYPE_VALUES = [
35
+ 'created', 'updated', 'deleted', 'email',
36
+ 'client-selected', // novo: troca de cliente no Hub
37
+ 'access-blocked', // novo: conta externa barrada pelo guard
38
+ ] as const;
39
+ export type LogType = (typeof LOG_TYPE_VALUES)[number];
40
+
41
+ @Schema({ _id: false })
42
+ export class LogTarget {
43
+ uid: string; // uid no Firebase do Hub (projeto hub-grapa)
44
+ email: string;
45
+ }
46
+
47
+ Log.reference: LogReference // @Prop com enum LOG_REFERENCE_VALUES
48
+ Log.type: LogType // @Prop com enum LOG_TYPE_VALUES
49
+ Log.target?: LogTarget | null // default null; preenchido só em reference 'hub-access'
50
+ ```
51
+
52
+ - `@ApiProperty` em `target` e nos dois enums.
53
+ - JSDoc em português no `target`: "Conta do Hub afetada pela ação. Vazio fora de `hub-access`. Ver GD-760."
54
+
55
+ Índice novo, para buscar o histórico de uma pessoa e para a trava de um alerta por hora da GD-762:
56
+
57
+ ```ts
58
+ LogSchema.index({ reference: 1, 'target.uid': 1, updatedAt: -1 });
59
+ ```
60
+
61
+ Os índices atuais (`{ referenceId: 1, reference: 1 }` e `{ reference: 1, updatedAt: -1 }`) ficam.
62
+
63
+ ---
64
+
65
+ ## Arquivos
66
+
67
+ - Alterar `src/schemas/log.schema.ts`: as duas constantes `as const` com o tipo derivado, a classe `LogTarget`, o campo `target` e o índice.
68
+ - Alterar `package.json`: versão nova (a última publicada hoje é a 1.0.236; conferir no npm antes).
69
+
70
+ ## Passos
71
+
72
+ 1. Trocar os enums inline de `reference` e `type` pelas constantes `LOG_REFERENCE_VALUES` e `LOG_TYPE_VALUES`, com os valores novos. Os valores antigos continuam, na mesma ordem.
73
+ 2. Criar `LogTarget` (`@Schema({ _id: false })`) e o campo `target` (`@Prop({ type: LogTarget, default: null })`), com `@ApiProperty` e o JSDoc.
74
+ 3. Declarar o índice `{ reference: 1, 'target.uid': 1, updatedAt: -1 }`.
75
+ 4. `npm run build` e conferir no `dist` as constantes, `LogTarget` e o índice, exportados pelo barrel (`src/index.ts` já faz `export *` do arquivo).
76
+ 5. Checar com `validateSync`, usando o `dist`:
77
+ - um Log antigo, sem `target`, continua válido;
78
+ - um Log com `reference: 'hub-access'`, `type: 'client-selected'` e `target` preenchido é válido;
79
+ - `type: 'qualquer'` continua inválido.
80
+ 6. Subir a versão no `package.json` e publicar (José).
81
+
82
+ ## Dependências
83
+
84
+ - Nenhuma. Esta Task vem antes da GD-762.
85
+
86
+ ## Validação
87
+
88
+ - `npm run build`.
89
+ - Script rápido de `validateSync` com o `dist` (passo 5).
90
+ - `npm view @grapadigital/shared-schemas version` antes de publicar.
91
+
92
+ ## Pontos abertos
93
+
94
+ - O DTO da api-logs (`create-log.dto.ts`) já aceita referências que o schema não tem (`influencer`, `profile`, `curation`, `prospect`). Isso não muda aqui: a GD-762 grava o Log direto pelo model e não passa pela api-logs.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grapadigital/shared-schemas",
3
- "version": "1.0.235",
3
+ "version": "1.0.237",
4
4
  "description": "Shared Mongoose Schemas",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -119,10 +119,6 @@ export class Metrics {
119
119
  @Prop({ type: Number, required: false, default: null })
120
120
  stickerTapCount?: number | null;
121
121
 
122
- /** Reposts do post (Primetag `private_metrics.reposts`, perfil conectado). 2026-10-24. */
123
- @Prop({ type: Number, required: false, default: null })
124
- repostCount?: number | null;
125
-
126
122
  @Prop({ type: Number, required: false, default: null })
127
123
  replyCount?: number | null;
128
124
 
@@ -13,6 +13,13 @@ export type LeadPresentationFormat = (typeof LEAD_PRESENTATION_FORMAT_VALUES)[nu
13
13
  export const LEAD_PAYMENT_TERM_VALUES = [30, 60, 90, 120] as const;
14
14
  export type LeadPaymentTerm = (typeof LEAD_PAYMENT_TERM_VALUES)[number];
15
15
 
16
+ export const LEAD_BILLING_MODEL_VALUES = [
17
+ 'transfer',
18
+ 'double_taxation',
19
+ 'direct_payment',
20
+ ] as const;
21
+ export type LeadBillingModel = (typeof LEAD_BILLING_MODEL_VALUES)[number];
22
+
16
23
  export const LEAD_DELIVERABLE_VALUES = [
17
24
  'content_strategy',
18
25
  'ppt_presentation',
@@ -116,6 +123,9 @@ export class LeadBudget {
116
123
  @Prop({ type: Number, enum: LEAD_PAYMENT_TERM_VALUES })
117
124
  paymentTerm?: LeadPaymentTerm;
118
125
 
126
+ @Prop({ type: String, enum: LEAD_BILLING_MODEL_VALUES })
127
+ billingModel?: LeadBillingModel;
128
+
119
129
  @Prop()
120
130
  campaignDurationMonths?: number;
121
131
  }
@@ -309,6 +319,14 @@ export class Lead {
309
319
  @Prop({ index: true })
310
320
  lastEditedAt?: Date;
311
321
 
322
+ /**
323
+ * Data de exclusão lógica (soft delete).
324
+ * Mantém o registro no banco de dados para fins de auditoria/histórico,
325
+ * mas deve ser desconsiderado nas consultas padrão (`deletedAt: null`).
326
+ */
327
+ @Prop({ index: true })
328
+ deletedAt?: Date;
329
+
312
330
  @Prop({ type: LeadGeneralSchema, default: {} })
313
331
  general: LeadGeneral;
314
332
 
@@ -1,8 +1,33 @@
1
1
  import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
2
+ import { ApiProperty } from '@nestjs/swagger';
2
3
  import { HydratedDocument, Schema as MongooseSchema, Types, model as MongooseModel } from 'mongoose';
3
4
 
4
5
  export type LogDocument = HydratedDocument<Log>;
5
6
 
7
+ export const LOG_REFERENCE_VALUES = [
8
+ 'action',
9
+ 'recruitment',
10
+ 'content',
11
+ 'contract',
12
+ 'sale',
13
+ 'invoice',
14
+ 'payment',
15
+ 'assignment',
16
+ 'commission',
17
+ 'hub-access',
18
+ ] as const;
19
+ export type LogReference = (typeof LOG_REFERENCE_VALUES)[number];
20
+
21
+ export const LOG_TYPE_VALUES = [
22
+ 'created',
23
+ 'updated',
24
+ 'deleted',
25
+ 'email',
26
+ 'client-selected',
27
+ 'access-blocked',
28
+ ] as const;
29
+ export type LogType = (typeof LOG_TYPE_VALUES)[number];
30
+
6
31
  @Schema({ _id: false })
7
32
  class UpdatedBy {
8
33
  @Prop({ required: true }) team: string;
@@ -10,6 +35,18 @@ class UpdatedBy {
10
35
  @Prop({ required: true }) email: string;
11
36
  }
12
37
 
38
+ @Schema({ _id: false })
39
+ export class LogTarget {
40
+ /** uid da conta no Firebase do Hub (projeto hub-grapa). */
41
+ @ApiProperty({ example: 'FmWcCgBLTwOR2YIEZ5toRdoRpGC3' })
42
+ @Prop({ required: true })
43
+ uid: string;
44
+
45
+ @ApiProperty({ example: 'pessoa@cliente.com.br' })
46
+ @Prop({ required: true })
47
+ email: string;
48
+ }
49
+
13
50
  @Schema()
14
51
  export class Log {
15
52
  @Prop({ type: MongooseSchema.Types.ObjectId, auto: true, required: false })
@@ -18,32 +55,13 @@ export class Log {
18
55
  @Prop({ type: MongooseSchema.Types.ObjectId })
19
56
  referenceId: string;
20
57
 
21
- @Prop({
22
- required: true,
23
- enum: [
24
- 'action',
25
- 'recruitment',
26
- 'content',
27
- 'contract',
28
- 'sale',
29
- 'invoice',
30
- 'payment',
31
- 'assignment',
32
- 'commission',
33
- ],
34
- })
35
- reference: 'action' | 'recruitment' | 'content' | 'contract' | 'sale' | 'invoice' | 'payment' | 'assignment' | 'commission';
36
-
37
- @Prop({
38
- required: true,
39
- enum: [
40
- 'created',
41
- 'updated',
42
- 'deleted',
43
- 'email'
44
- ],
45
- })
46
- type: 'created' | 'updated' | 'deleted' | 'email';
58
+ @ApiProperty({ enum: LOG_REFERENCE_VALUES })
59
+ @Prop({ required: true, enum: LOG_REFERENCE_VALUES })
60
+ reference: LogReference;
61
+
62
+ @ApiProperty({ enum: LOG_TYPE_VALUES })
63
+ @Prop({ required: true, enum: LOG_TYPE_VALUES })
64
+ type: LogType;
47
65
 
48
66
  @Prop({ required: false }) phase?: string;
49
67
 
@@ -55,11 +73,19 @@ export class Log {
55
73
 
56
74
  @Prop({ type: UpdatedBy })
57
75
  updatedBy?: UpdatedBy;
76
+
77
+ /**
78
+ * Conta do Hub afetada pela ação. Vazio fora de `hub-access`. Ver GD-760.
79
+ */
80
+ @ApiProperty({ type: LogTarget, required: false, nullable: true })
81
+ @Prop({ type: LogTarget, default: null })
82
+ target?: LogTarget | null;
58
83
  }
59
84
 
60
85
  export const LogSchema = SchemaFactory.createForClass(Log);
61
86
 
62
87
  LogSchema.index({ referenceId: 1, reference: 1 });
63
88
  LogSchema.index({ reference: 1, updatedAt: -1 });
89
+ LogSchema.index({ reference: 1, 'target.uid': 1, updatedAt: -1 });
64
90
 
65
91
  export const LogModel = MongooseModel('Log', LogSchema);