@grapadigital/shared-schemas 1.0.241 → 1.1.0
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/index.d.ts +42 -42
- package/dist/schemas/action.schema.d.ts +13 -38
- package/dist/schemas/action.schema.js +81 -64
- package/dist/schemas/assignment.schema.d.ts +6 -31
- package/dist/schemas/assignment.schema.js +44 -44
- package/dist/schemas/benchmark.schema.d.ts +5 -30
- package/dist/schemas/benchmark.schema.js +11 -6
- package/dist/schemas/campaign.schema.d.ts +4 -29
- package/dist/schemas/campaign.schema.js +4 -4
- package/dist/schemas/client.schema.d.ts +30 -91
- package/dist/schemas/client.schema.js +73 -71
- package/dist/schemas/comment.schema.d.ts +9 -34
- package/dist/schemas/comment.schema.js +42 -37
- package/dist/schemas/commission.schema.d.ts +7 -32
- package/dist/schemas/commission.schema.js +10 -10
- package/dist/schemas/content-capture-process.schema.d.ts +12 -37
- package/dist/schemas/content-capture-process.schema.js +24 -17
- package/dist/schemas/content-draft.schema.d.ts +4 -29
- package/dist/schemas/content-draft.schema.js +5 -5
- package/dist/schemas/content.schema.d.ts +20 -45
- package/dist/schemas/content.schema.js +84 -74
- package/dist/schemas/contract.schema.d.ts +5 -30
- package/dist/schemas/contract.schema.js +5 -5
- package/dist/schemas/creative.schema.d.ts +11 -36
- package/dist/schemas/creative.schema.js +22 -31
- package/dist/schemas/export-comments-job.schema.d.ts +4 -29
- package/dist/schemas/export-comments-job.schema.js +6 -6
- package/dist/schemas/group.schema.d.ts +2 -27
- package/dist/schemas/group.schema.js +5 -5
- package/dist/schemas/influencer.schema.d.ts +12 -37
- package/dist/schemas/influencer.schema.js +16 -18
- package/dist/schemas/invoice.schema.d.ts +6 -31
- package/dist/schemas/invoice.schema.js +42 -32
- package/dist/schemas/job.schema.d.ts +4 -29
- package/dist/schemas/job.schema.js +14 -14
- package/dist/schemas/lead.schema.d.ts +15 -40
- package/dist/schemas/lead.schema.js +67 -64
- package/dist/schemas/log.schema.d.ts +3 -28
- package/dist/schemas/log.schema.js +24 -24
- package/dist/schemas/note.schema.d.ts +3 -28
- package/dist/schemas/note.schema.js +9 -9
- package/dist/schemas/notifications.schema.d.ts +3 -28
- package/dist/schemas/notifications.schema.js +8 -8
- package/dist/schemas/organization.schema.d.ts +2 -27
- package/dist/schemas/organization.schema.js +4 -4
- package/dist/schemas/party.schema.d.ts +6 -31
- package/dist/schemas/party.schema.js +11 -11
- package/dist/schemas/payment.schema.d.ts +20 -45
- package/dist/schemas/payment.schema.js +63 -54
- package/dist/schemas/profile.schema.d.ts +5 -30
- package/dist/schemas/profile.schema.js +6 -6
- package/dist/schemas/project.schema.d.ts +9 -34
- package/dist/schemas/project.schema.js +13 -13
- package/dist/schemas/prospect.schema.d.ts +6 -31
- package/dist/schemas/prospect.schema.js +9 -9
- package/dist/schemas/recruitment.schema.d.ts +19 -44
- package/dist/schemas/recruitment.schema.js +36 -36
- package/dist/schemas/responsible.schema.d.ts +1 -27
- package/dist/schemas/responsible.schema.js +6 -6
- package/dist/schemas/sale.schema.d.ts +19 -44
- package/dist/schemas/sale.schema.js +43 -51
- package/dist/schemas/script.schema.d.ts +11 -36
- package/dist/schemas/script.schema.js +21 -30
- package/dist/schemas/snapshot.schema.d.ts +5 -30
- package/dist/schemas/snapshot.schema.js +6 -6
- package/dist/schemas/store-visit.schema.d.ts +3 -28
- package/dist/schemas/store-visit.schema.js +21 -17
- package/dist/schemas/store.schema.d.ts +5 -30
- package/dist/schemas/store.schema.js +8 -8
- package/dist/schemas/supplier.schema.d.ts +4 -29
- package/dist/schemas/supplier.schema.js +3 -3
- package/dist/schemas/tag.schema.d.ts +2 -27
- package/dist/schemas/tag.schema.js +5 -5
- package/dist/schemas/task.schema.d.ts +11 -36
- package/dist/schemas/task.schema.js +67 -67
- package/dist/schemas/token.schema.d.ts +3 -28
- package/dist/schemas/token.schema.js +3 -3
- package/dist/schemas/trigger.schema.d.ts +3 -28
- package/dist/schemas/trigger.schema.js +5 -5
- package/dist/schemas/user.schema.d.ts +3 -28
- package/dist/schemas/user.schema.js +7 -7
- package/dist/schemas/webhook.schema.d.ts +6 -31
- package/dist/schemas/webhook.schema.js +10 -10
- package/dist/utils/merge-metrics-breakdown.util.d.ts +1 -1
- package/dist/utils/merge-metrics-breakdown.util.js +7 -2
- package/dist/utils/normalize-content-link.util.js +7 -7
- package/package.json +29 -16
- package/.eslintrc.json +0 -28
- package/.prettierrc +0 -4
- package/dist/schemas/profile-followers-snapshot.schema.d.ts +0 -67
- package/dist/schemas/profile-followers-snapshot.schema.js +0 -65
- package/dist/schemas/schedule.schema.d.ts +0 -73
- package/dist/schemas/schedule.schema.js +0 -116
- package/dist/utils/cost-per-impact.util.d.ts +0 -37
- package/dist/utils/cost-per-impact.util.js +0 -72
- package/dist/utils/influencer-contract.util.d.ts +0 -32
- package/dist/utils/influencer-contract.util.js +0 -77
- package/docs/code-review.md +0 -27
- package/docs/constitution.md +0 -75
- package/docs/specs/GD-692.md +0 -112
- package/docs/specs/GD-761.md +0 -94
- package/index.d.ts +0 -3
- package/src/index.ts +0 -42
- package/src/schemas/action.schema.ts +0 -328
- package/src/schemas/assignment.schema.ts +0 -154
- package/src/schemas/benchmark.schema.ts +0 -39
- package/src/schemas/campaign.schema.ts +0 -38
- package/src/schemas/client.schema.ts +0 -319
- package/src/schemas/comment.schema.ts +0 -216
- package/src/schemas/commission.schema.ts +0 -108
- package/src/schemas/content-capture-process.schema.ts +0 -195
- package/src/schemas/content-draft.schema.ts +0 -49
- package/src/schemas/content.schema.ts +0 -688
- package/src/schemas/contract.schema.ts +0 -44
- package/src/schemas/creative.schema.ts +0 -256
- package/src/schemas/export-comments-job.schema.ts +0 -59
- package/src/schemas/group.schema.ts +0 -23
- package/src/schemas/influencer.schema.ts +0 -184
- package/src/schemas/invoice.schema.ts +0 -164
- package/src/schemas/job.schema.ts +0 -111
- package/src/schemas/lead.schema.ts +0 -372
- package/src/schemas/log.schema.ts +0 -91
- package/src/schemas/note.schema.ts +0 -34
- package/src/schemas/notifications.schema.ts +0 -61
- package/src/schemas/organization.schema.ts +0 -29
- package/src/schemas/party.schema.ts +0 -65
- package/src/schemas/payment.schema.ts +0 -275
- package/src/schemas/profile.schema.ts +0 -77
- package/src/schemas/project.schema.ts +0 -116
- package/src/schemas/prospect.schema.ts +0 -62
- package/src/schemas/recruitment.schema.ts +0 -277
- package/src/schemas/responsible.schema.ts +0 -27
- package/src/schemas/sale.schema.ts +0 -297
- package/src/schemas/script.schema.ts +0 -235
- package/src/schemas/snapshot.schema.ts +0 -55
- package/src/schemas/store-visit.schema.ts +0 -68
- package/src/schemas/store.schema.ts +0 -52
- package/src/schemas/supplier.schema.ts +0 -12
- package/src/schemas/tag.schema.ts +0 -26
- package/src/schemas/task.schema.ts +0 -205
- package/src/schemas/token.schema.ts +0 -42
- package/src/schemas/trigger.schema.ts +0 -48
- package/src/schemas/user.schema.ts +0 -59
- package/src/schemas/webhook.schema.ts +0 -81
- package/src/utils/merge-metrics-breakdown.util.ts +0 -51
- package/src/utils/normalize-content-link.util.ts +0 -31
- package/tsconfig.build.json +0 -5
- package/tsconfig.json +0 -29
|
@@ -3,7 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.mergeMetricsBreakdown = void 0;
|
|
4
4
|
const content_schema_1 = require("../schemas/content.schema");
|
|
5
5
|
// Partes que, se digitadas à mão, fazem o engajamento virar a soma.
|
|
6
|
-
const ENGAGEMENT_KEYS = [
|
|
6
|
+
const ENGAGEMENT_KEYS = [
|
|
7
|
+
"likeCount",
|
|
8
|
+
"commentCount",
|
|
9
|
+
"shareCount",
|
|
10
|
+
"savedCount",
|
|
11
|
+
];
|
|
7
12
|
const sumParts = (organic, boosted) => organic == null && boosted == null ? null : (organic ?? 0) + (boosted ?? 0);
|
|
8
13
|
/**
|
|
9
14
|
* Totais de Content.metrics a partir da divisão Orgânico e Impulsionado. Ver GD-707.
|
|
@@ -25,7 +30,7 @@ const mergeMetricsBreakdown = (breakdown, primetagEngagementCount, manualMetrics
|
|
|
25
30
|
const hasManualEngagement = ENGAGEMENT_KEYS.some((key) => manualMetrics.includes(`organic.${key}`) || manualMetrics.includes(`boosted.${key}`));
|
|
26
31
|
const engagementCount = hasManualEngagement
|
|
27
32
|
? ENGAGEMENT_KEYS.reduce((sum, key) => sum + (totals[key] ?? 0), 0)
|
|
28
|
-
: primetagEngagementCount ?? null;
|
|
33
|
+
: (primetagEngagementCount ?? null);
|
|
29
34
|
const impressionCount = totals.impressionCount ?? 0;
|
|
30
35
|
return {
|
|
31
36
|
...totals,
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.normalizeContentLink = void 0;
|
|
4
4
|
// Hosts cujo link não é de um post (ex.: pasta do Drive com os stories): não
|
|
5
5
|
// geram chave, senão posts diferentes casariam pelo mesmo link.
|
|
6
|
-
const NON_POST_HOSTS = [
|
|
6
|
+
const NON_POST_HOSTS = ["drive.google.com", "docs.google.com"];
|
|
7
7
|
/**
|
|
8
8
|
* Link do post sem protocolo, www./m., query, âncora e barra final. Mantém
|
|
9
9
|
* maiúsculas: o código do post (ex.: /reel/DCx8kQ2) diferencia. É a chave para
|
|
@@ -16,15 +16,15 @@ const NON_POST_HOSTS = ['drive.google.com', 'docs.google.com'];
|
|
|
16
16
|
* A mesma regra está em scripts/lib/normalize-content-link.js: as duas mudam juntas.
|
|
17
17
|
*/
|
|
18
18
|
const normalizeContentLink = (link) => {
|
|
19
|
-
const raw = String(link ??
|
|
19
|
+
const raw = String(link ?? "")
|
|
20
20
|
.trim()
|
|
21
|
-
.replace(/^https?:\/\/(www\.|m\.)?/i,
|
|
22
|
-
const clean = raw.replace(/[?#].*$/,
|
|
23
|
-
const [host, ...segments] = clean.split(
|
|
21
|
+
.replace(/^https?:\/\/(www\.|m\.)?/i, "");
|
|
22
|
+
const clean = raw.replace(/[?#].*$/, "").replace(/\/+$/, "");
|
|
23
|
+
const [host, ...segments] = clean.split("/");
|
|
24
24
|
if (!host || NON_POST_HOSTS.includes(host.toLowerCase()))
|
|
25
25
|
return null;
|
|
26
|
-
if (/^youtube\.com$/i.test(host) && segments[0] ===
|
|
27
|
-
const videoId =
|
|
26
|
+
if (/^youtube\.com$/i.test(host) && segments[0] === "watch") {
|
|
27
|
+
const videoId = /[?&]v=([^&#]+)/.exec(raw)?.[1];
|
|
28
28
|
return videoId ? `${host}/watch?v=${videoId}` : null;
|
|
29
29
|
}
|
|
30
30
|
const minSegments = /^youtu\.be$/i.test(host) ? 1 : 2;
|
package/package.json
CHANGED
|
@@ -1,29 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grapadigital/shared-schemas",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Shared Mongoose Schemas",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
},
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"@nestjs/mongoose": "^11.0.1",
|
|
13
|
-
"@nestjs/swagger": "^11.2.0",
|
|
14
|
-
"@typescript-eslint/eslint-plugin": "^8.24.0",
|
|
15
|
-
"@typescript-eslint/parser": "^8.24.0",
|
|
16
|
-
"eslint": "^9.20.1",
|
|
17
|
-
"eslint-config-prettier": "^10.0.1",
|
|
18
|
-
"eslint-plugin-prettier": "^5.2.3",
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"@nestjs/mongoose": "^10.0.0 || ^11.0.0",
|
|
9
|
+
"@nestjs/swagger": "^7.4.0 || ^11.0.0",
|
|
19
10
|
"mongoose": "^8.10.1"
|
|
20
11
|
},
|
|
21
12
|
"devDependencies": {
|
|
22
|
-
"
|
|
13
|
+
"@grapadigital/shared-config": "^0.1.0",
|
|
14
|
+
"@nestjs/mongoose": "^11.0.1",
|
|
15
|
+
"@nestjs/swagger": "^11.2.0",
|
|
16
|
+
"@types/node": "^22.20.5",
|
|
17
|
+
"eslint": "^10.14.0",
|
|
18
|
+
"mongoose": "^8.10.1",
|
|
19
|
+
"prettier": "^3.9.10",
|
|
20
|
+
"typescript": "^5.9.3"
|
|
23
21
|
},
|
|
24
22
|
"repository": {
|
|
25
23
|
"type": "git",
|
|
26
24
|
"url": "https://github.com/grapadigital/shared-schemas"
|
|
27
25
|
},
|
|
28
|
-
"license": "MIT"
|
|
29
|
-
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"prettier": "@grapadigital/shared-config/prettier",
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
36
|
+
"lint": "eslint .",
|
|
37
|
+
"lint:fix": "eslint . --fix",
|
|
38
|
+
"format": "prettier --write .",
|
|
39
|
+
"format:check": "prettier --check .",
|
|
40
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/.eslintrc.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"browser": true,
|
|
4
|
-
"es2021": true,
|
|
5
|
-
"node": true
|
|
6
|
-
},
|
|
7
|
-
"parser": "@typescript-eslint/parser",
|
|
8
|
-
"parserOptions": {
|
|
9
|
-
"ecmaVersion": "latest",
|
|
10
|
-
"sourceType": "module"
|
|
11
|
-
},
|
|
12
|
-
"extends": [
|
|
13
|
-
"eslint:recommended",
|
|
14
|
-
"plugin:@typescript-eslint/recommended",
|
|
15
|
-
"prettier"
|
|
16
|
-
],
|
|
17
|
-
"plugins": ["@typescript-eslint", "prettier"],
|
|
18
|
-
"rules": {
|
|
19
|
-
"prettier/prettier": "error",
|
|
20
|
-
"@typescript-eslint/no-unused-vars": [
|
|
21
|
-
"error",
|
|
22
|
-
{ "argsIgnorePattern": "^_" }
|
|
23
|
-
],
|
|
24
|
-
"@typescript-eslint/explicit-function-return-type": "off",
|
|
25
|
-
"@typescript-eslint/no-explicit-any": "warn",
|
|
26
|
-
"@typescript-eslint/no-non-null-assertion": "warn"
|
|
27
|
-
}
|
|
28
|
-
}
|
package/.prettierrc
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
-
/// <reference types="mongoose/types/callback" />
|
|
3
|
-
/// <reference types="mongoose/types/collection" />
|
|
4
|
-
/// <reference types="mongoose/types/connection" />
|
|
5
|
-
/// <reference types="mongoose/types/cursor" />
|
|
6
|
-
/// <reference types="mongoose/types/document" />
|
|
7
|
-
/// <reference types="mongoose/types/error" />
|
|
8
|
-
/// <reference types="mongoose/types/expressions" />
|
|
9
|
-
/// <reference types="mongoose/types/helpers" />
|
|
10
|
-
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
-
/// <reference types="mongoose/types/indexes" />
|
|
12
|
-
/// <reference types="mongoose/types/models" />
|
|
13
|
-
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
-
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
-
/// <reference types="mongoose/types/populate" />
|
|
16
|
-
/// <reference types="mongoose/types/query" />
|
|
17
|
-
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
-
/// <reference types="mongoose/types/session" />
|
|
19
|
-
/// <reference types="mongoose/types/types" />
|
|
20
|
-
/// <reference types="mongoose/types/utility" />
|
|
21
|
-
/// <reference types="mongoose/types/validation" />
|
|
22
|
-
/// <reference types="mongoose/types/virtuals" />
|
|
23
|
-
/// <reference types="mongoose/types/schematypes" />
|
|
24
|
-
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
-
/// <reference types="mongoose/types/inferrawdoctype" />
|
|
26
|
-
import { HydratedDocument, Schema as MongooseSchema, Types } from 'mongoose';
|
|
27
|
-
import { Profile } from './profile.schema';
|
|
28
|
-
export type ProfileFollowersSnapshotDocument = HydratedDocument<ProfileFollowersSnapshot>;
|
|
29
|
-
/**
|
|
30
|
-
* Histórico diário de seguidores por perfil, gravado pelo profile-sync-worker
|
|
31
|
-
* a partir do `audience_size` que a Primetag devolve na captura. Um doc por
|
|
32
|
-
* perfil por dia (`date` truncado em UTC): o trigger roda várias vezes ao dia
|
|
33
|
-
* e cada rodada só sobrescreve o valor do dia.
|
|
34
|
-
*/
|
|
35
|
-
export declare class ProfileFollowersSnapshot {
|
|
36
|
-
_id?: Types.ObjectId;
|
|
37
|
-
profile: Types.ObjectId | Profile;
|
|
38
|
-
socialnetwork?: string;
|
|
39
|
-
followers: number;
|
|
40
|
-
date: Date;
|
|
41
|
-
capturedAt: Date;
|
|
42
|
-
source: 'primetag';
|
|
43
|
-
createdAt?: Date;
|
|
44
|
-
updatedAt?: Date;
|
|
45
|
-
}
|
|
46
|
-
export declare const ProfileFollowersSnapshotSchema: MongooseSchema<ProfileFollowersSnapshot, import("mongoose").Model<ProfileFollowersSnapshot, any, any, any, import("mongoose").Document<unknown, any, ProfileFollowersSnapshot, any, {}> & ProfileFollowersSnapshot & Required<{
|
|
47
|
-
_id: Types.ObjectId;
|
|
48
|
-
}> & {
|
|
49
|
-
__v: number;
|
|
50
|
-
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, ProfileFollowersSnapshot, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<ProfileFollowersSnapshot>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<ProfileFollowersSnapshot> & Required<{
|
|
51
|
-
_id: Types.ObjectId;
|
|
52
|
-
}> & {
|
|
53
|
-
__v: number;
|
|
54
|
-
}>;
|
|
55
|
-
export declare const ProfileFollowersSnapshotModel: import("mongoose").Model<ProfileFollowersSnapshot, {}, {}, {}, import("mongoose").Document<unknown, {}, ProfileFollowersSnapshot, {}, import("mongoose").DefaultSchemaOptions> & ProfileFollowersSnapshot & Required<{
|
|
56
|
-
_id: Types.ObjectId;
|
|
57
|
-
}> & {
|
|
58
|
-
__v: number;
|
|
59
|
-
}, MongooseSchema<ProfileFollowersSnapshot, import("mongoose").Model<ProfileFollowersSnapshot, any, any, any, import("mongoose").Document<unknown, any, ProfileFollowersSnapshot, any, {}> & ProfileFollowersSnapshot & Required<{
|
|
60
|
-
_id: Types.ObjectId;
|
|
61
|
-
}> & {
|
|
62
|
-
__v: number;
|
|
63
|
-
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, ProfileFollowersSnapshot, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<ProfileFollowersSnapshot>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<ProfileFollowersSnapshot> & Required<{
|
|
64
|
-
_id: Types.ObjectId;
|
|
65
|
-
}> & {
|
|
66
|
-
__v: number;
|
|
67
|
-
}>>;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ProfileFollowersSnapshotModel = exports.ProfileFollowersSnapshotSchema = exports.ProfileFollowersSnapshot = void 0;
|
|
13
|
-
const mongoose_1 = require("@nestjs/mongoose");
|
|
14
|
-
const mongoose_2 = require("mongoose");
|
|
15
|
-
/**
|
|
16
|
-
* Histórico diário de seguidores por perfil, gravado pelo profile-sync-worker
|
|
17
|
-
* a partir do `audience_size` que a Primetag devolve na captura. Um doc por
|
|
18
|
-
* perfil por dia (`date` truncado em UTC): o trigger roda várias vezes ao dia
|
|
19
|
-
* e cada rodada só sobrescreve o valor do dia.
|
|
20
|
-
*/
|
|
21
|
-
let ProfileFollowersSnapshot = class ProfileFollowersSnapshot {
|
|
22
|
-
};
|
|
23
|
-
__decorate([
|
|
24
|
-
(0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.ObjectId, auto: true, required: false }),
|
|
25
|
-
__metadata("design:type", mongoose_2.Types.ObjectId)
|
|
26
|
-
], ProfileFollowersSnapshot.prototype, "_id", void 0);
|
|
27
|
-
__decorate([
|
|
28
|
-
(0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.ObjectId, ref: 'Profile', required: true }),
|
|
29
|
-
__metadata("design:type", Object)
|
|
30
|
-
], ProfileFollowersSnapshot.prototype, "profile", void 0);
|
|
31
|
-
__decorate([
|
|
32
|
-
(0, mongoose_1.Prop)({ type: String, required: false }),
|
|
33
|
-
__metadata("design:type", String)
|
|
34
|
-
], ProfileFollowersSnapshot.prototype, "socialnetwork", void 0);
|
|
35
|
-
__decorate([
|
|
36
|
-
(0, mongoose_1.Prop)({ type: Number, required: true }),
|
|
37
|
-
__metadata("design:type", Number)
|
|
38
|
-
], ProfileFollowersSnapshot.prototype, "followers", void 0);
|
|
39
|
-
__decorate([
|
|
40
|
-
(0, mongoose_1.Prop)({ type: Date, required: true }),
|
|
41
|
-
__metadata("design:type", Date)
|
|
42
|
-
], ProfileFollowersSnapshot.prototype, "date", void 0);
|
|
43
|
-
__decorate([
|
|
44
|
-
(0, mongoose_1.Prop)({ type: Date, required: true }),
|
|
45
|
-
__metadata("design:type", Date)
|
|
46
|
-
], ProfileFollowersSnapshot.prototype, "capturedAt", void 0);
|
|
47
|
-
__decorate([
|
|
48
|
-
(0, mongoose_1.Prop)({ type: String, enum: ['primetag'], required: true, default: 'primetag' }),
|
|
49
|
-
__metadata("design:type", String)
|
|
50
|
-
], ProfileFollowersSnapshot.prototype, "source", void 0);
|
|
51
|
-
__decorate([
|
|
52
|
-
(0, mongoose_1.Prop)({ default: Date.now, required: false }),
|
|
53
|
-
__metadata("design:type", Date)
|
|
54
|
-
], ProfileFollowersSnapshot.prototype, "createdAt", void 0);
|
|
55
|
-
__decorate([
|
|
56
|
-
(0, mongoose_1.Prop)({ default: Date.now, required: false }),
|
|
57
|
-
__metadata("design:type", Date)
|
|
58
|
-
], ProfileFollowersSnapshot.prototype, "updatedAt", void 0);
|
|
59
|
-
ProfileFollowersSnapshot = __decorate([
|
|
60
|
-
(0, mongoose_1.Schema)({ collection: 'profile-followers-snapshots', timestamps: true })
|
|
61
|
-
], ProfileFollowersSnapshot);
|
|
62
|
-
exports.ProfileFollowersSnapshot = ProfileFollowersSnapshot;
|
|
63
|
-
exports.ProfileFollowersSnapshotSchema = mongoose_1.SchemaFactory.createForClass(ProfileFollowersSnapshot);
|
|
64
|
-
exports.ProfileFollowersSnapshotSchema.index({ profile: 1, date: 1 }, { unique: true });
|
|
65
|
-
exports.ProfileFollowersSnapshotModel = (0, mongoose_2.model)('ProfileFollowersSnapshot', exports.ProfileFollowersSnapshotSchema);
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
-
/// <reference types="mongoose/types/callback" />
|
|
3
|
-
/// <reference types="mongoose/types/collection" />
|
|
4
|
-
/// <reference types="mongoose/types/connection" />
|
|
5
|
-
/// <reference types="mongoose/types/cursor" />
|
|
6
|
-
/// <reference types="mongoose/types/document" />
|
|
7
|
-
/// <reference types="mongoose/types/error" />
|
|
8
|
-
/// <reference types="mongoose/types/expressions" />
|
|
9
|
-
/// <reference types="mongoose/types/helpers" />
|
|
10
|
-
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
-
/// <reference types="mongoose/types/indexes" />
|
|
12
|
-
/// <reference types="mongoose/types/models" />
|
|
13
|
-
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
-
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
-
/// <reference types="mongoose/types/populate" />
|
|
16
|
-
/// <reference types="mongoose/types/query" />
|
|
17
|
-
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
-
/// <reference types="mongoose/types/session" />
|
|
19
|
-
/// <reference types="mongoose/types/types" />
|
|
20
|
-
/// <reference types="mongoose/types/utility" />
|
|
21
|
-
/// <reference types="mongoose/types/validation" />
|
|
22
|
-
/// <reference types="mongoose/types/virtuals" />
|
|
23
|
-
/// <reference types="mongoose/types/schematypes" />
|
|
24
|
-
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
-
/// <reference types="mongoose/types/inferrawdoctype" />
|
|
26
|
-
import { HydratedDocument, Schema as MongooseSchema, Types } from 'mongoose';
|
|
27
|
-
import { Action } from './action.schema';
|
|
28
|
-
import { Client } from './client.schema';
|
|
29
|
-
import { Content } from './content.schema';
|
|
30
|
-
import { Influencer } from './influencer.schema';
|
|
31
|
-
import { Profile } from './profile.schema';
|
|
32
|
-
import { Recruitment } from './recruitment.schema';
|
|
33
|
-
export type ScheduleDocument = HydratedDocument<Schedule>;
|
|
34
|
-
export declare class Schedule {
|
|
35
|
-
_id?: Types.ObjectId;
|
|
36
|
-
recruitment: Types.ObjectId | Recruitment;
|
|
37
|
-
profile: Types.ObjectId | Profile;
|
|
38
|
-
influencer: Types.ObjectId | Influencer;
|
|
39
|
-
socialnetwork: string;
|
|
40
|
-
type: 'post' | 'task';
|
|
41
|
-
format?: string;
|
|
42
|
-
briefing?: string;
|
|
43
|
-
requiredTags?: string;
|
|
44
|
-
referenceLink?: string;
|
|
45
|
-
observation?: string;
|
|
46
|
-
scheduledAt: Date;
|
|
47
|
-
status: 'scheduled' | 'published' | 'late' | 'cancelled';
|
|
48
|
-
contentId?: Types.ObjectId | Content;
|
|
49
|
-
action: Types.ObjectId | Action;
|
|
50
|
-
client: Types.ObjectId | Client;
|
|
51
|
-
}
|
|
52
|
-
export declare const ScheduleSchema: MongooseSchema<Schedule, import("mongoose").Model<Schedule, any, any, any, import("mongoose").Document<unknown, any, Schedule, any, {}> & Schedule & Required<{
|
|
53
|
-
_id: Types.ObjectId;
|
|
54
|
-
}> & {
|
|
55
|
-
__v: number;
|
|
56
|
-
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, Schedule, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<Schedule>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<Schedule> & Required<{
|
|
57
|
-
_id: Types.ObjectId;
|
|
58
|
-
}> & {
|
|
59
|
-
__v: number;
|
|
60
|
-
}>;
|
|
61
|
-
export declare const ScheduleModel: import("mongoose").Model<Schedule, {}, {}, {}, import("mongoose").Document<unknown, {}, Schedule, {}, import("mongoose").DefaultSchemaOptions> & Schedule & Required<{
|
|
62
|
-
_id: Types.ObjectId;
|
|
63
|
-
}> & {
|
|
64
|
-
__v: number;
|
|
65
|
-
}, MongooseSchema<Schedule, import("mongoose").Model<Schedule, any, any, any, import("mongoose").Document<unknown, any, Schedule, any, {}> & Schedule & Required<{
|
|
66
|
-
_id: Types.ObjectId;
|
|
67
|
-
}> & {
|
|
68
|
-
__v: number;
|
|
69
|
-
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, Schedule, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<Schedule>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<Schedule> & Required<{
|
|
70
|
-
_id: Types.ObjectId;
|
|
71
|
-
}> & {
|
|
72
|
-
__v: number;
|
|
73
|
-
}>>;
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ScheduleModel = exports.ScheduleSchema = exports.Schedule = void 0;
|
|
13
|
-
const mongoose_1 = require("@nestjs/mongoose");
|
|
14
|
-
const swagger_1 = require("@nestjs/swagger");
|
|
15
|
-
const mongoose_2 = require("mongoose");
|
|
16
|
-
let Schedule = class Schedule {
|
|
17
|
-
};
|
|
18
|
-
__decorate([
|
|
19
|
-
(0, swagger_1.ApiProperty)({ example: '64bfc3a78d3f1e2a12345670' }),
|
|
20
|
-
(0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.ObjectId, auto: true, required: false }),
|
|
21
|
-
__metadata("design:type", mongoose_2.Types.ObjectId)
|
|
22
|
-
], Schedule.prototype, "_id", void 0);
|
|
23
|
-
__decorate([
|
|
24
|
-
(0, swagger_1.ApiProperty)({ example: '64bfc3a78d3f1e2a12345678' }),
|
|
25
|
-
(0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.ObjectId, ref: 'Recruitment', required: true }),
|
|
26
|
-
__metadata("design:type", Object)
|
|
27
|
-
], Schedule.prototype, "recruitment", void 0);
|
|
28
|
-
__decorate([
|
|
29
|
-
(0, swagger_1.ApiProperty)({ example: '64bfc3a78d3f1e2a12345679' }),
|
|
30
|
-
(0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.ObjectId, ref: 'Profile', required: true }),
|
|
31
|
-
__metadata("design:type", Object)
|
|
32
|
-
], Schedule.prototype, "profile", void 0);
|
|
33
|
-
__decorate([
|
|
34
|
-
(0, swagger_1.ApiProperty)({ example: '64bfc3a78d3f1e2a12345683' }),
|
|
35
|
-
(0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.ObjectId, ref: 'Influencer', required: true }),
|
|
36
|
-
__metadata("design:type", Object)
|
|
37
|
-
], Schedule.prototype, "influencer", void 0);
|
|
38
|
-
__decorate([
|
|
39
|
-
(0, swagger_1.ApiProperty)({ example: 'instagram' }),
|
|
40
|
-
(0, mongoose_1.Prop)({ type: String, required: true }),
|
|
41
|
-
__metadata("design:type", String)
|
|
42
|
-
], Schedule.prototype, "socialnetwork", void 0);
|
|
43
|
-
__decorate([
|
|
44
|
-
(0, swagger_1.ApiProperty)({ enum: ['post', 'task'], example: 'post' }),
|
|
45
|
-
(0, mongoose_1.Prop)({ type: String, enum: ['post', 'task'], required: true }),
|
|
46
|
-
__metadata("design:type", String)
|
|
47
|
-
], Schedule.prototype, "type", void 0);
|
|
48
|
-
__decorate([
|
|
49
|
-
(0, swagger_1.ApiProperty)({ example: 'reel', required: false }),
|
|
50
|
-
(0, mongoose_1.Prop)({
|
|
51
|
-
type: String,
|
|
52
|
-
required: function () {
|
|
53
|
-
return this.type === 'post';
|
|
54
|
-
},
|
|
55
|
-
}),
|
|
56
|
-
__metadata("design:type", String)
|
|
57
|
-
], Schedule.prototype, "format", void 0);
|
|
58
|
-
__decorate([
|
|
59
|
-
(0, swagger_1.ApiProperty)({ example: 'Mostrar o produto em uso, destacar a promoção', required: false }),
|
|
60
|
-
(0, mongoose_1.Prop)({ type: String, required: false }),
|
|
61
|
-
__metadata("design:type", String)
|
|
62
|
-
], Schedule.prototype, "briefing", void 0);
|
|
63
|
-
__decorate([
|
|
64
|
-
(0, swagger_1.ApiProperty)({ example: '@marca, #publi, #ad', required: false }),
|
|
65
|
-
(0, mongoose_1.Prop)({ type: String, required: false }),
|
|
66
|
-
__metadata("design:type", String)
|
|
67
|
-
], Schedule.prototype, "requiredTags", void 0);
|
|
68
|
-
__decorate([
|
|
69
|
-
(0, swagger_1.ApiProperty)({ example: 'https://drive.google.com/...', required: false }),
|
|
70
|
-
(0, mongoose_1.Prop)({ type: String, required: false }),
|
|
71
|
-
__metadata("design:type", String)
|
|
72
|
-
], Schedule.prototype, "referenceLink", void 0);
|
|
73
|
-
__decorate([
|
|
74
|
-
(0, swagger_1.ApiProperty)({ example: 'Confirmar com o cliente antes de publicar', required: false }),
|
|
75
|
-
(0, mongoose_1.Prop)({ type: String, required: false }),
|
|
76
|
-
__metadata("design:type", String)
|
|
77
|
-
], Schedule.prototype, "observation", void 0);
|
|
78
|
-
__decorate([
|
|
79
|
-
(0, swagger_1.ApiProperty)({ example: '2025-11-05T14:00:00.000Z' }),
|
|
80
|
-
(0, mongoose_1.Prop)({ type: Date, required: true }),
|
|
81
|
-
__metadata("design:type", Date)
|
|
82
|
-
], Schedule.prototype, "scheduledAt", void 0);
|
|
83
|
-
__decorate([
|
|
84
|
-
(0, swagger_1.ApiProperty)({ enum: ['scheduled', 'published', 'late', 'cancelled'], example: 'scheduled' }),
|
|
85
|
-
(0, mongoose_1.Prop)({
|
|
86
|
-
type: String,
|
|
87
|
-
enum: ['scheduled', 'published', 'late', 'cancelled'],
|
|
88
|
-
required: true,
|
|
89
|
-
}),
|
|
90
|
-
__metadata("design:type", String)
|
|
91
|
-
], Schedule.prototype, "status", void 0);
|
|
92
|
-
__decorate([
|
|
93
|
-
(0, swagger_1.ApiProperty)({ example: '64bfc3a78d3f1e2a12345680', required: false }),
|
|
94
|
-
(0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.ObjectId, ref: 'Content', required: false }),
|
|
95
|
-
__metadata("design:type", Object)
|
|
96
|
-
], Schedule.prototype, "contentId", void 0);
|
|
97
|
-
__decorate([
|
|
98
|
-
(0, swagger_1.ApiProperty)({ example: '64bfc3a78d3f1e2a12345681' }),
|
|
99
|
-
(0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.ObjectId, ref: 'Action', required: true }),
|
|
100
|
-
__metadata("design:type", Object)
|
|
101
|
-
], Schedule.prototype, "action", void 0);
|
|
102
|
-
__decorate([
|
|
103
|
-
(0, swagger_1.ApiProperty)({ example: '64bfc3a78d3f1e2a12345682' }),
|
|
104
|
-
(0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.ObjectId, ref: 'Client', required: true }),
|
|
105
|
-
__metadata("design:type", Object)
|
|
106
|
-
], Schedule.prototype, "client", void 0);
|
|
107
|
-
Schedule = __decorate([
|
|
108
|
-
(0, mongoose_1.Schema)({ timestamps: true })
|
|
109
|
-
], Schedule);
|
|
110
|
-
exports.Schedule = Schedule;
|
|
111
|
-
exports.ScheduleSchema = mongoose_1.SchemaFactory.createForClass(Schedule);
|
|
112
|
-
exports.ScheduleSchema.index({ action: 1, scheduledAt: 1 });
|
|
113
|
-
exports.ScheduleSchema.index({ client: 1 });
|
|
114
|
-
exports.ScheduleSchema.index({ recruitment: 1 });
|
|
115
|
-
exports.ScheduleSchema.index({ influencer: 1 });
|
|
116
|
-
exports.ScheduleModel = (0, mongoose_2.model)('Schedule', exports.ScheduleSchema);
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { InfluencerContract } from '../schemas/influencer.schema';
|
|
2
|
-
export declare const getEngagementRatePercent: (totals: {
|
|
3
|
-
engagement: number;
|
|
4
|
-
potentialReach: number;
|
|
5
|
-
}) => number | null;
|
|
6
|
-
export declare const getCostPerImpact: (input: {
|
|
7
|
-
value: number;
|
|
8
|
-
engagementRatePercent: number | null;
|
|
9
|
-
impressions: number;
|
|
10
|
-
posts: number;
|
|
11
|
-
}) => number | null;
|
|
12
|
-
export interface ContractMonthTotals {
|
|
13
|
-
year: number;
|
|
14
|
-
month: number;
|
|
15
|
-
posts: number;
|
|
16
|
-
impressions: number;
|
|
17
|
-
engagement: number;
|
|
18
|
-
potentialReach: number;
|
|
19
|
-
}
|
|
20
|
-
export interface MonthlyCostPerImpact extends ContractMonthTotals {
|
|
21
|
-
monthlyValue: number;
|
|
22
|
-
monthlyCostPerImpact: number | null;
|
|
23
|
-
engagementRatePercent: number | null;
|
|
24
|
-
elapsedMonths: number;
|
|
25
|
-
accumulatedSpend: number;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Série mensal acumulada desde o mês de início até `untilMonth` (inclusive):
|
|
29
|
-
* gasto acumulado = valor mensal × meses decorridos; métricas somadas desde o
|
|
30
|
-
* início. `monthlyTotals` traz os totais de cada mês (não acumulados).
|
|
31
|
-
*/
|
|
32
|
-
export declare const getMonthlyCostPerImpactSeries: (contract: Pick<InfluencerContract, 'value' | 'productsValue' | 'startDate' | 'endDate' | 'amendments' | 'status' | 'isActive'>, monthlyTotals: ContractMonthTotals[], until: {
|
|
33
|
-
year: number;
|
|
34
|
-
month: number;
|
|
35
|
-
}) => MonthlyCostPerImpact[];
|
|
36
|
-
/** Média dos CPIs mensais não nulos. */
|
|
37
|
-
export declare const getAverageMonthlyCostPerImpact: (series: MonthlyCostPerImpact[]) => number | null;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAverageMonthlyCostPerImpact = exports.getMonthlyCostPerImpactSeries = exports.getCostPerImpact = exports.getEngagementRatePercent = void 0;
|
|
4
|
-
const influencer_contract_util_1 = require("./influencer-contract.util");
|
|
5
|
-
/**
|
|
6
|
-
* CPI (Custo por Impacto), como no genc (`TB_Contratos_Influencer_Cliente` e
|
|
7
|
-
* `TB_CPI_Mensal_Contrato`). Ver GD-715.
|
|
8
|
-
* CPI = valor ÷ ((E/R% ÷ 100) × impressões × posts), E/R% = engajamento ÷ alcance potencial × 100.
|
|
9
|
-
*/
|
|
10
|
-
const round = (value, places) => Math.round(value * 10 ** places) / 10 ** places;
|
|
11
|
-
const getEngagementRatePercent = (totals) => totals.potentialReach > 0 ? (totals.engagement / totals.potentialReach) * 100 : null;
|
|
12
|
-
exports.getEngagementRatePercent = getEngagementRatePercent;
|
|
13
|
-
const getCostPerImpact = (input) => {
|
|
14
|
-
const { value, engagementRatePercent, impressions, posts } = input;
|
|
15
|
-
if (!engagementRatePercent || engagementRatePercent <= 0 || value <= 0)
|
|
16
|
-
return null;
|
|
17
|
-
const divisor = (engagementRatePercent / 100) * impressions * posts;
|
|
18
|
-
return divisor > 0 ? round(value / divisor, 6) : null;
|
|
19
|
-
};
|
|
20
|
-
exports.getCostPerImpact = getCostPerImpact;
|
|
21
|
-
/**
|
|
22
|
-
* Série mensal acumulada desde o mês de início até `untilMonth` (inclusive):
|
|
23
|
-
* gasto acumulado = valor mensal × meses decorridos; métricas somadas desde o
|
|
24
|
-
* início. `monthlyTotals` traz os totais de cada mês (não acumulados).
|
|
25
|
-
*/
|
|
26
|
-
const getMonthlyCostPerImpactSeries = (contract, monthlyTotals, until) => {
|
|
27
|
-
const brt = new Date(new Date(contract.startDate).getTime() - 3 * 60 * 60 * 1000);
|
|
28
|
-
let year = brt.getUTCFullYear();
|
|
29
|
-
let month = brt.getUTCMonth() + 1;
|
|
30
|
-
const monthlyValue = (0, influencer_contract_util_1.getContractMonthlyValue)(contract);
|
|
31
|
-
const byMonth = new Map(monthlyTotals.map((t) => [`${t.year}-${t.month}`, t]));
|
|
32
|
-
const acc = { posts: 0, impressions: 0, engagement: 0, potentialReach: 0 };
|
|
33
|
-
const series = [];
|
|
34
|
-
let elapsedMonths = 0;
|
|
35
|
-
while (year < until.year || (year === until.year && month <= until.month)) {
|
|
36
|
-
elapsedMonths += 1;
|
|
37
|
-
const totals = byMonth.get(`${year}-${month}`);
|
|
38
|
-
if (totals) {
|
|
39
|
-
acc.posts += totals.posts;
|
|
40
|
-
acc.impressions += totals.impressions;
|
|
41
|
-
acc.engagement += totals.engagement;
|
|
42
|
-
acc.potentialReach += totals.potentialReach;
|
|
43
|
-
}
|
|
44
|
-
const accumulatedSpend = round(monthlyValue * elapsedMonths, 2);
|
|
45
|
-
const engagementRatePercent = acc.posts > 0 ? (0, exports.getEngagementRatePercent)(acc) : null;
|
|
46
|
-
series.push({
|
|
47
|
-
year,
|
|
48
|
-
month,
|
|
49
|
-
...acc,
|
|
50
|
-
monthlyValue,
|
|
51
|
-
elapsedMonths,
|
|
52
|
-
accumulatedSpend,
|
|
53
|
-
engagementRatePercent: engagementRatePercent == null ? null : round(engagementRatePercent, 4),
|
|
54
|
-
monthlyCostPerImpact: acc.posts > 0 && acc.engagement > 0
|
|
55
|
-
? (0, exports.getCostPerImpact)({ value: accumulatedSpend, engagementRatePercent, impressions: acc.impressions, posts: acc.posts })
|
|
56
|
-
: null,
|
|
57
|
-
});
|
|
58
|
-
month += 1;
|
|
59
|
-
if (month > 12) {
|
|
60
|
-
month = 1;
|
|
61
|
-
year += 1;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return series;
|
|
65
|
-
};
|
|
66
|
-
exports.getMonthlyCostPerImpactSeries = getMonthlyCostPerImpactSeries;
|
|
67
|
-
/** Média dos CPIs mensais não nulos. */
|
|
68
|
-
const getAverageMonthlyCostPerImpact = (series) => {
|
|
69
|
-
const values = series.map((row) => row.monthlyCostPerImpact).filter((v) => v != null);
|
|
70
|
-
return values.length > 0 ? round(values.reduce((a, b) => a + b, 0) / values.length, 6) : null;
|
|
71
|
-
};
|
|
72
|
-
exports.getAverageMonthlyCostPerImpact = getAverageMonthlyCostPerImpact;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { InfluencerContract } from '../schemas/influencer.schema';
|
|
2
|
-
type ContractLike = Pick<InfluencerContract, 'value' | 'productsValue' | 'startDate' | 'endDate' | 'amendments' | 'status' | 'isActive'> & {
|
|
3
|
-
client?: unknown;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Fim efetivo da vigência: o maior entre o fim do Contrato e o fim dos Aditivos
|
|
7
|
-
* ativos (o Aditivo estende a vigência). null = Contrato em aberto, mesmo com
|
|
8
|
-
* Aditivo. Ver GD-715.
|
|
9
|
-
*/
|
|
10
|
-
export declare const getContractEndDate: (contract: ContractLike) => Date | null;
|
|
11
|
-
/**
|
|
12
|
-
* Início do dia seguinte ao fim da vigência em São Paulo (limite exclusivo):
|
|
13
|
-
* o último dia conta inteiro. null = Contrato em aberto.
|
|
14
|
-
*/
|
|
15
|
-
export declare const getContractEndExclusive: (contract: ContractLike) => Date | null;
|
|
16
|
-
/**
|
|
17
|
-
* Meses de vigência como no genc (`calcular_meses_vigencia`): anos × 12 + meses
|
|
18
|
-
* e mais 1 se sobrar dia; mínimo 1. Sem fim, conta até `now`.
|
|
19
|
-
* Ex.: 10/06/2025 a 11/02/2027 = 21; 15/03 a 14/09 = 6.
|
|
20
|
-
*/
|
|
21
|
-
export declare const getContractMonths: (contract: ContractLike, now?: Date) => number;
|
|
22
|
-
/** Cachê + produtos + Aditivos ativos. */
|
|
23
|
-
export declare const getContractTotalValue: (contract: ContractLike) => number;
|
|
24
|
-
/** Total ÷ meses de vigência, 2 casas (428.392,93 ÷ 21 = 20.399,66). */
|
|
25
|
-
export declare const getContractMonthlyValue: (contract: ContractLike, now?: Date) => number;
|
|
26
|
-
/** Ativo e assinado (status ausente conta como assinado). */
|
|
27
|
-
export declare const isContractUsable: (contract: ContractLike) => boolean;
|
|
28
|
-
/** Contrato usável do cliente vigente em `at`, com o último dia inteiro (sem fim = em aberto). */
|
|
29
|
-
export declare const getActiveContract: <T extends ContractLike>(influencer: {
|
|
30
|
-
contracts?: T[] | null | undefined;
|
|
31
|
-
} | null | undefined, clientId: unknown, at: Date) => T | null;
|
|
32
|
-
export {};
|