@grapadigital/shared-schemas 1.0.236 → 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.
- package/dist/schemas/log.schema.d.ts +15 -2
- package/dist/schemas/log.schema.js +48 -24
- package/docs/specs/GD-761.md +94 -0
- package/package.json +1 -1
- package/src/schemas/log.schema.ts +52 -26
|
@@ -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:
|
|
37
|
-
type:
|
|
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,
|
|
44
|
-
|
|
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,
|
|
61
|
-
|
|
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,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
|
-
@
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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);
|