@wrcb/cb-common 1.0.430 → 1.0.432

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export declare function isValidMongoId(id: string): boolean;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isValidMongoId = isValidMongoId;
7
+ const server_1 = require("@wrcb/cb-common/server");
8
+ const mongoose_1 = __importDefault(require("mongoose"));
9
+ function isValidMongoId(id) {
10
+ if (!mongoose_1.default.Types.ObjectId.isValid(id)) {
11
+ throw new server_1.BadRequestError('InvalidFeedPostId');
12
+ }
13
+ return true;
14
+ }
@@ -0,0 +1 @@
1
+ export declare function isValidTenant(tenant: any): boolean;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidTenant = isValidTenant;
4
+ const cb_common_1 = require("@wrcb/cb-common");
5
+ const server_1 = require("@wrcb/cb-common/server");
6
+ function isValidTenant(tenant) {
7
+ // Verificar se tenant existe e é string
8
+ if (!tenant || typeof tenant !== 'string') {
9
+ throw new server_1.BadRequestError('TenantRequired');
10
+ }
11
+ // Verificar se é um tenant válido
12
+ if (!Object.values(cb_common_1.Tenant).includes(tenant)) {
13
+ throw new server_1.BadRequestError('InvalidTenant');
14
+ }
15
+ return true;
16
+ }
package/build/server.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './helpers/createIdMongoose';
2
2
  export * from './helpers/authHelper';
3
- export * from './helpers/createObjects';
3
+ export * from './helpers/isValidMongoId';
4
+ export * from './helpers/isValidTenant';
4
5
  export * from './errors/badRequestError';
5
6
  export * from './errors/customError';
6
7
  export * from './errors/databaseConnectionError';
package/build/server.js CHANGED
@@ -16,7 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./helpers/createIdMongoose"), exports);
18
18
  __exportStar(require("./helpers/authHelper"), exports);
19
- __exportStar(require("./helpers/createObjects"), exports);
19
+ __exportStar(require("./helpers/isValidMongoId"), exports);
20
+ __exportStar(require("./helpers/isValidTenant"), exports);
20
21
  __exportStar(require("./errors/badRequestError"), exports);
21
22
  __exportStar(require("./errors/customError"), exports);
22
23
  __exportStar(require("./errors/databaseConnectionError"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrcb/cb-common",
3
- "version": "1.0.430",
3
+ "version": "1.0.432",
4
4
  "description": "Common resources between services",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -1,33 +0,0 @@
1
- import { MarketStatus } from '../types/marketStatus';
2
- import { OddType } from '../types/oddType';
3
- import { PredictionOptions } from '../types/predictions';
4
- import { PredictionStatus } from '../types/predictionStatus';
5
- export declare function BuildMarketObject(title?: string, description?: string, status?: MarketStatus, priority?: number): {
6
- title: string;
7
- description: string;
8
- status: MarketStatus;
9
- priority: number;
10
- };
11
- export declare function BuildPredictionObject(market: any, predictionOptions?: any, title?: string, details?: string, status?: PredictionStatus, deadLine?: Date, oddType?: OddType, image?: string, rules?: string, slug?: string): {
12
- title: string;
13
- details: string;
14
- status: PredictionStatus;
15
- deadLine: Date;
16
- oddType: OddType;
17
- image: string;
18
- rules: string;
19
- slug: string;
20
- market: any;
21
- predictionOptions: any;
22
- };
23
- export declare function BuildPredictionOptionsTwoOptionsArray(): PredictionOptions[];
24
- export declare function BuildPredictionOptionsMultipleOptionsArray(): PredictionOptions[];
25
- export declare function BuildBetObject(prediction: any, userId: string, value?: number, odd?: number): {
26
- prediction: any;
27
- userId: string;
28
- value: number;
29
- odd: number;
30
- description: string;
31
- optionId: string;
32
- optionLabel: string;
33
- };
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BuildMarketObject = BuildMarketObject;
4
- exports.BuildPredictionObject = BuildPredictionObject;
5
- exports.BuildPredictionOptionsTwoOptionsArray = BuildPredictionOptionsTwoOptionsArray;
6
- exports.BuildPredictionOptionsMultipleOptionsArray = BuildPredictionOptionsMultipleOptionsArray;
7
- exports.BuildBetObject = BuildBetObject;
8
- const uuid_1 = require("uuid");
9
- const marketStatus_1 = require("../types/marketStatus");
10
- const oddType_1 = require("../types/oddType");
11
- const predictionStatus_1 = require("../types/predictionStatus");
12
- const createIdMongoose_1 = require("./createIdMongoose");
13
- function BuildMarketObject(title, description, status, priority) {
14
- return {
15
- title: title !== null && title !== void 0 ? title : 'Politics',
16
- description: description !== null && description !== void 0 ? description : 'Politics predictions',
17
- status: status !== null && status !== void 0 ? status : marketStatus_1.MarketStatus.Active,
18
- priority: priority !== null && priority !== void 0 ? priority : 1
19
- };
20
- }
21
- function BuildPredictionObject(market, predictionOptions, title, details, status, deadLine, oddType, image, rules, slug) {
22
- return {
23
- title: title !== null && title !== void 0 ? title : 'Will Donald Trump win?',
24
- details: details !== null && details !== void 0 ? details : 'prediction about elections',
25
- status: status !== null && status !== void 0 ? status : predictionStatus_1.PredictionStatus.Created,
26
- deadLine: deadLine !== null && deadLine !== void 0 ? deadLine : new Date(),
27
- oddType: oddType !== null && oddType !== void 0 ? oddType : oddType_1.OddType.Automatic05,
28
- image: image !== null && image !== void 0 ? image : 'image',
29
- rules: rules !== null && rules !== void 0 ? rules : 'rules',
30
- slug: slug !== null && slug !== void 0 ? slug : 'slug',
31
- market,
32
- predictionOptions: predictionOptions !== null && predictionOptions !== void 0 ? predictionOptions : BuildPredictionOptionsTwoOptionsArray()
33
- };
34
- }
35
- function BuildPredictionOptionsTwoOptionsArray() {
36
- const predictionOptionsTwoOptions = [
37
- {
38
- description: 'Teremos cadeirada no marçal?',
39
- options: [
40
- {
41
- optionId: (0, uuid_1.v4)(),
42
- optionLabel: 'Sim',
43
- optionWinner: false,
44
- optionInitialOdd: 0
45
- },
46
- {
47
- optionId: (0, uuid_1.v4)(),
48
- optionLabel: 'Não',
49
- optionWinner: false,
50
- optionInitialOdd: 0
51
- }
52
- ]
53
- }
54
- ];
55
- return predictionOptionsTwoOptions;
56
- }
57
- function BuildPredictionOptionsMultipleOptionsArray() {
58
- const predictionOptionsMultiOptions = [];
59
- return predictionOptionsMultiOptions;
60
- }
61
- function BuildBetObject(prediction, userId, value, odd) {
62
- return {
63
- prediction,
64
- userId: userId !== null && userId !== void 0 ? userId : (0, createIdMongoose_1.createIdMongoose)(),
65
- value: value !== null && value !== void 0 ? value : 150,
66
- odd: odd !== null && odd !== void 0 ? odd : 1.5,
67
- description: 'descricao',
68
- optionId: '3124',
69
- optionLabel: 'Sim'
70
- };
71
- }