c2-climbing-x 1.0.30 → 1.0.31

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.
@@ -8,6 +8,7 @@ export declare enum TicketStatus {
8
8
  }
9
9
  export interface ITicket {
10
10
  _id: Types.ObjectId;
11
+ code: string;
11
12
  account: Types.ObjectId | IAccount;
12
13
  challenge: Types.ObjectId | IChallenge;
13
14
  status: TicketStatus;
@@ -9,6 +9,7 @@ var TicketStatus;
9
9
  TicketStatus["DROPPED"] = "DROPPED";
10
10
  })(TicketStatus || (exports.TicketStatus = TicketStatus = {}));
11
11
  exports.TicketSchema = new mongoose_1.Schema({
12
+ code: { type: String, required: true },
12
13
  account: { type: mongoose_1.Schema.Types.ObjectId, ref: "account", required: true },
13
14
  challenge: { type: mongoose_1.Schema.Types.ObjectId, ref: "challenge", required: true },
14
15
  status: { type: String, required: true, enum: TicketStatus },
@@ -0,0 +1 @@
1
+ export * from "./utils";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1,5 @@
1
+ export declare const generateCode: (length: number, uppercase?: CASE_SENSITIVE, prefix?: string) => string;
2
+ export declare enum CASE_SENSITIVE {
3
+ UPPER_CASE = 0,
4
+ LOWER_CASE = 1
5
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.CASE_SENSITIVE = exports.generateCode = void 0;
37
+ const crypto = __importStar(require("crypto"));
38
+ const generateCode = (length, uppercase = CASE_SENSITIVE.LOWER_CASE, prefix = "") => {
39
+ const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
40
+ const charsetLength = charset.length;
41
+ const randomBytesBuffer = crypto.randomBytes(length);
42
+ let code = prefix;
43
+ // Converte cada byte aleatório em um caractere alfanumérico
44
+ for (let i = 0; i < length; i++) {
45
+ const randomIndex = randomBytesBuffer[i] % charsetLength;
46
+ code += charset[randomIndex];
47
+ }
48
+ // const code = `${prefix}${crypto.randomBytes(length).toString("hex")}`
49
+ if (uppercase === CASE_SENSITIVE.UPPER_CASE) {
50
+ return code.toUpperCase();
51
+ }
52
+ return code;
53
+ };
54
+ exports.generateCode = generateCode;
55
+ var CASE_SENSITIVE;
56
+ (function (CASE_SENSITIVE) {
57
+ CASE_SENSITIVE[CASE_SENSITIVE["UPPER_CASE"] = 0] = "UPPER_CASE";
58
+ CASE_SENSITIVE[CASE_SENSITIVE["LOWER_CASE"] = 1] = "LOWER_CASE";
59
+ })(CASE_SENSITIVE || (exports.CASE_SENSITIVE = CASE_SENSITIVE = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-climbing-x",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "description": "Modelagem TypeScript/Mongoose para o jogo Escalada X (times, campeonatos, fases, rodadas, confrontos, desafios)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,5 +29,8 @@
29
29
  "championship",
30
30
  "challenge"
31
31
  ],
32
- "license": "MIT"
32
+ "license": "MIT",
33
+ "dependencies": {
34
+ "crypto": "^1.0.1"
35
+ }
33
36
  }