@merkaly/api 0.2.5-6 → 0.2.5-7

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.
Files changed (196) hide show
  1. package/.output/abstracts/abstract.entity.d.ts +14 -0
  2. package/.output/abstracts/abstract.validator.d.ts +24 -0
  3. package/.output/abstracts/abstract.validator.js +118 -0
  4. package/.output/exceptions/missing-identity.exception.d.ts +5 -0
  5. package/.output/exceptions/missing-identity.exception.js +30 -0
  6. package/.output/modules/asset/files/file.entity.d.ts +9 -0
  7. package/.output/modules/asset/files/file.schema.d.ts +34 -0
  8. package/.output/modules/asset/files/file.schema.js +10 -0
  9. package/.output/modules/auth/organizations/organization.entity.d.ts +8 -0
  10. package/.output/modules/auth/users/user.entity.d.ts +9 -0
  11. package/.output/modules/auth/users/user.schema.d.ts +34 -0
  12. package/.output/modules/auth/users/user.schema.js +10 -0
  13. package/.output/modules/auth/users/user.validator.d.ts +12 -0
  14. package/.output/modules/auth/users/user.validator.js +58 -0
  15. package/.output/modules/inventory/brands/brand.entity.d.ts +6 -0
  16. package/.output/modules/inventory/brands/brand.schema.d.ts +34 -0
  17. package/.output/modules/inventory/brands/brand.schema.js +10 -0
  18. package/.output/modules/inventory/brands/brand.validator.d.ts +11 -0
  19. package/.output/modules/inventory/brands/brand.validator.js +74 -0
  20. package/.output/modules/inventory/categories/category.entity.d.ts +6 -0
  21. package/.output/modules/inventory/categories/category.schema.d.ts +34 -0
  22. package/.output/modules/inventory/categories/category.schema.js +10 -0
  23. package/.output/modules/inventory/categories/category.validator.d.ts +8 -0
  24. package/.output/modules/inventory/categories/category.validator.js +42 -0
  25. package/.output/modules/inventory/complements/complement.entity.d.ts +6 -0
  26. package/.output/modules/inventory/complements/complement.validator.d.ts +10 -0
  27. package/.output/modules/inventory/complements/complement.validator.js +52 -0
  28. package/.output/modules/inventory/products/documents/attribute.document.d.ts +5 -0
  29. package/.output/modules/inventory/products/documents/attribute.document.js +33 -0
  30. package/.output/modules/inventory/products/documents/dimension.document.d.ts +6 -0
  31. package/.output/modules/inventory/products/documents/dimension.document.js +35 -0
  32. package/.output/modules/inventory/products/product.entity.d.ts +19 -0
  33. package/.output/modules/inventory/products/product.schema.d.ts +34 -0
  34. package/.output/modules/inventory/products/product.schema.js +18 -0
  35. package/.output/modules/inventory/products/product.validator.d.ts +29 -0
  36. package/.output/modules/inventory/products/product.validator.js +179 -0
  37. package/.output/modules/inventory/products/validators/attributes.validator.d.ts +5 -0
  38. package/.output/modules/inventory/products/validators/attributes.validator.js +35 -0
  39. package/.output/modules/inventory/products/validators/dimension.validator.d.ts +6 -0
  40. package/.output/modules/inventory/products/validators/dimension.validator.js +38 -0
  41. package/.output/modules/sale/customers/customer.entity.d.ts +8 -0
  42. package/.output/modules/sale/customers/customer.schema.d.ts +34 -0
  43. package/.output/modules/sale/customers/customer.schema.js +10 -0
  44. package/.output/modules/sale/customers/customer.validator.d.ts +14 -0
  45. package/.output/modules/sale/customers/customer.validator.js +94 -0
  46. package/.output/modules/sale/orders/documents/address.document.d.ts +8 -0
  47. package/.output/modules/sale/orders/documents/address.document.js +43 -0
  48. package/.output/modules/sale/orders/documents/status.document.d.ts +8 -0
  49. package/.output/modules/sale/orders/documents/status.document.js +34 -0
  50. package/.output/modules/sale/orders/entities/item.entity.d.ts +38 -0
  51. package/.output/modules/sale/orders/enums/order.status.d.ts +6 -0
  52. package/.output/modules/sale/orders/enums/order.status.js +10 -0
  53. package/.output/modules/sale/orders/order.entity.d.ts +21 -0
  54. package/.output/modules/sale/orders/order.validator.d.ts +16 -0
  55. package/.output/modules/sale/orders/order.validator.js +86 -0
  56. package/.output/modules/sale/orders/validators/address.validator.d.ts +17 -0
  57. package/.output/modules/sale/orders/validators/address.validator.js +81 -0
  58. package/{src/modules/sale/orders/validators/billing.validator.ts → .output/modules/sale/orders/validators/billing.validator.d.ts} +4 -7
  59. package/.output/modules/sale/orders/validators/billing.validator.js +13 -0
  60. package/.output/modules/sale/orders/validators/item.validator.d.ts +5 -0
  61. package/.output/modules/sale/orders/validators/item.validator.js +32 -0
  62. package/.output/modules/sale/orders/validators/payment.validator.d.ts +10 -0
  63. package/.output/modules/sale/orders/validators/payment.validator.js +62 -0
  64. package/.output/modules/sale/orders/validators/shipping.validator.d.ts +9 -0
  65. package/.output/modules/sale/orders/validators/shipping.validator.js +14 -0
  66. package/.output/modules/sale/payments/entities/status.entity.d.ts +8 -0
  67. package/.output/modules/sale/payments/enums/billing.type.d.ts +6 -0
  68. package/.output/modules/sale/payments/enums/billing.type.js +10 -0
  69. package/.output/modules/sale/payments/enums/payment.status.d.ts +7 -0
  70. package/.output/modules/sale/payments/enums/payment.status.js +11 -0
  71. package/.output/modules/sale/payments/enums/shipping.type.d.ts +4 -0
  72. package/.output/modules/sale/payments/enums/shipping.type.js +8 -0
  73. package/.output/modules/sale/payments/payment.entity.d.ts +12 -0
  74. package/.output/modules/sale/payments/payment.schema.d.ts +34 -0
  75. package/.output/modules/sale/payments/payment.schema.js +14 -0
  76. package/.output/modules/sale/payments/payment.validator.d.ts +16 -0
  77. package/.output/modules/sale/payments/payment.validator.js +77 -0
  78. package/.output/tsconfig.package.tsbuildinfo +1 -0
  79. package/package.json +4 -1
  80. package/.bin/deploy.sh +0 -9
  81. package/.bin/package.sh +0 -12
  82. package/.docker/Dockerfile +0 -21
  83. package/.dockerignore +0 -12
  84. package/.github/dependabot.yml +0 -17
  85. package/.github/semantic.yml +0 -5
  86. package/.github/workflows/pull_request.yml +0 -35
  87. package/.prettierrc +0 -5
  88. package/app.ts +0 -11
  89. package/authCertificate.pem +0 -19
  90. package/nest-cli.json +0 -8
  91. package/src/abstracts/abstarct.repository.ts +0 -62
  92. package/src/abstracts/abstract.controller.ts +0 -18
  93. package/src/abstracts/abstract.entity.ts +0 -22
  94. package/src/abstracts/abstract.router.ts +0 -7
  95. package/src/abstracts/abstract.validator.ts +0 -61
  96. package/src/app.config.ts +0 -59
  97. package/src/app.console.ts +0 -24
  98. package/src/app.guard.ts +0 -39
  99. package/src/app.module.ts +0 -54
  100. package/src/app.strategy.ts +0 -21
  101. package/src/commands/seed.command.ts +0 -263
  102. package/src/decorators/public.decorator.ts +0 -5
  103. package/src/decorators/user.decorator.ts +0 -30
  104. package/src/exceptions/missing-identity.exception.ts +0 -11
  105. package/src/interceptors/mongoose.interceptor.ts +0 -63
  106. package/src/main.ts +0 -27
  107. package/src/middlewares/router.middleware.ts +0 -14
  108. package/src/modules/asset/asset.module.ts +0 -19
  109. package/src/modules/asset/files/file.controller.ts +0 -22
  110. package/src/modules/asset/files/file.entity.ts +0 -24
  111. package/src/modules/asset/files/file.module.ts +0 -21
  112. package/src/modules/asset/files/file.repository.ts +0 -44
  113. package/src/modules/asset/files/file.schema.ts +0 -8
  114. package/src/modules/asset/files/file.service.ts +0 -4
  115. package/src/modules/auth/auth.controller.ts +0 -57
  116. package/src/modules/auth/auth.module.ts +0 -20
  117. package/src/modules/auth/organizations/organization.controller.ts +0 -20
  118. package/src/modules/auth/organizations/organization.entity.ts +0 -22
  119. package/src/modules/auth/organizations/organization.module.ts +0 -21
  120. package/src/modules/auth/organizations/organization.repository.ts +0 -16
  121. package/src/modules/auth/organizations/organization.schema.ts +0 -8
  122. package/src/modules/auth/users/user.controller.ts +0 -23
  123. package/src/modules/auth/users/user.entity.ts +0 -25
  124. package/src/modules/auth/users/user.module.ts +0 -20
  125. package/src/modules/auth/users/user.repository.ts +0 -79
  126. package/src/modules/auth/users/user.schema.ts +0 -8
  127. package/src/modules/auth/users/user.validator.ts +0 -32
  128. package/src/modules/command.module.ts +0 -15
  129. package/src/modules/global.module.ts +0 -46
  130. package/src/modules/inventory/brands/brand.controller.ts +0 -44
  131. package/src/modules/inventory/brands/brand.entity.ts +0 -20
  132. package/src/modules/inventory/brands/brand.module.ts +0 -20
  133. package/src/modules/inventory/brands/brand.repository.ts +0 -40
  134. package/src/modules/inventory/brands/brand.schema.ts +0 -8
  135. package/src/modules/inventory/brands/brand.validator.ts +0 -31
  136. package/src/modules/inventory/categories/category.controller.ts +0 -42
  137. package/src/modules/inventory/categories/category.entity.ts +0 -15
  138. package/src/modules/inventory/categories/category.module.ts +0 -19
  139. package/src/modules/inventory/categories/category.repository.ts +0 -34
  140. package/src/modules/inventory/categories/category.schema.ts +0 -8
  141. package/src/modules/inventory/categories/category.validator.ts +0 -20
  142. package/src/modules/inventory/complements/complement.controller.ts +0 -41
  143. package/src/modules/inventory/complements/complement.entity.ts +0 -15
  144. package/src/modules/inventory/complements/complement.module.ts +0 -19
  145. package/src/modules/inventory/complements/complement.repository.ts +0 -37
  146. package/src/modules/inventory/complements/complement.schema.ts +0 -8
  147. package/src/modules/inventory/complements/complement.validator.ts +0 -28
  148. package/src/modules/inventory/inventory.module.ts +0 -23
  149. package/src/modules/inventory/products/documents/attribute.document.ts +0 -14
  150. package/src/modules/inventory/products/documents/dimension.document.ts +0 -16
  151. package/src/modules/inventory/products/product.controller.ts +0 -62
  152. package/src/modules/inventory/products/product.entity.ts +0 -46
  153. package/src/modules/inventory/products/product.module.ts +0 -19
  154. package/src/modules/inventory/products/product.repository.ts +0 -64
  155. package/src/modules/inventory/products/product.schema.ts +0 -19
  156. package/src/modules/inventory/products/product.validator.ts +0 -132
  157. package/src/modules/inventory/products/validators/attributes.validator.ts +0 -15
  158. package/src/modules/inventory/products/validators/dimension.validator.ts +0 -19
  159. package/src/modules/sale/customers/customer.controller.ts +0 -41
  160. package/src/modules/sale/customers/customer.entity.ts +0 -19
  161. package/src/modules/sale/customers/customer.module.ts +0 -18
  162. package/src/modules/sale/customers/customer.repository.ts +0 -30
  163. package/src/modules/sale/customers/customer.schema.ts +0 -8
  164. package/src/modules/sale/customers/customer.validator.ts +0 -43
  165. package/src/modules/sale/orders/documents/address.document.ts +0 -22
  166. package/src/modules/sale/orders/documents/status.document.ts +0 -17
  167. package/src/modules/sale/orders/entities/item.entity.ts +0 -24
  168. package/src/modules/sale/orders/enums/order.status.ts +0 -6
  169. package/src/modules/sale/orders/order.controller.ts +0 -65
  170. package/src/modules/sale/orders/order.entity.ts +0 -46
  171. package/src/modules/sale/orders/order.module.ts +0 -22
  172. package/src/modules/sale/orders/order.repository.ts +0 -122
  173. package/src/modules/sale/orders/order.schema.ts +0 -36
  174. package/src/modules/sale/orders/order.validator.ts +0 -44
  175. package/src/modules/sale/orders/validators/address.validator.ts +0 -50
  176. package/src/modules/sale/orders/validators/item.validator.ts +0 -14
  177. package/src/modules/sale/orders/validators/payment.validator.ts +0 -44
  178. package/src/modules/sale/orders/validators/shipping.validator.ts +0 -14
  179. package/src/modules/sale/payments/entities/status.entity.ts +0 -17
  180. package/src/modules/sale/payments/enums/billing.type.ts +0 -6
  181. package/src/modules/sale/payments/enums/payment.status.ts +0 -7
  182. package/src/modules/sale/payments/enums/shipping.type.ts +0 -4
  183. package/src/modules/sale/payments/payment.controller.ts +0 -45
  184. package/src/modules/sale/payments/payment.entity.ts +0 -25
  185. package/src/modules/sale/payments/payment.module.ts +0 -20
  186. package/src/modules/sale/payments/payment.repository.ts +0 -57
  187. package/src/modules/sale/payments/payment.schema.ts +0 -14
  188. package/src/modules/sale/payments/payment.validator.ts +0 -32
  189. package/src/modules/sale/sale.module.ts +0 -20
  190. package/src/services/auth0.service.ts +0 -49
  191. package/src/services/mongo.service.ts +0 -52
  192. package/test/auth/auth.spec.ts +0 -20
  193. package/test/main.ts +0 -12
  194. package/tsconfig.build.json +0 -4
  195. package/tsconfig.json +0 -21
  196. package/tsconfig.package.json +0 -22
package/.prettierrc DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "printWidth": 120,
3
- "singleQuote": true,
4
- "trailingComma": "all"
5
- }
package/app.ts DELETED
@@ -1,11 +0,0 @@
1
- import { INestApplication, ValidationPipe } from '@nestjs/common';
2
- import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
3
-
4
- export function createNestApp(app: INestApplication) {
5
- const config = new DocumentBuilder().build();
6
-
7
- const document = SwaggerModule.createDocument(app, config);
8
- SwaggerModule.setup('/', app, document);
9
-
10
- return app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
11
- }
@@ -1,19 +0,0 @@
1
- -----BEGIN CERTIFICATE-----
2
- MIIDAzCCAeugAwIBAgIJHHJE5ykX1iXdMA0GCSqGSIb3DQEBCwUAMB8xHTAbBgNV
3
- BAMTFG1lcmthbHkudXMuYXV0aDAuY29tMB4XDTIwMTEwNTIwMzY1MVoXDTM0MDcx
4
- NTIwMzY1MVowHzEdMBsGA1UEAxMUbWVya2FseS51cy5hdXRoMC5jb20wggEiMA0G
5
- CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCcZcJZ3OxWI+Gxp9a5GGY9035+FulG
6
- 8+EWuIvRMCL1cUT5RMfib5/I66T3wipHw8t/yKO/Rjdx8uRUTZE94OuCbSI/qK7R
7
- bQHdpvUw9B9W3lwwyJ+AjklDOYS91apJcn4g/poMQ5G9vdQsP6u1P176Bjkx0pxH
8
- qx3XBbPf61IIb7Jv1yiyc6sQDHyR3ZUQPrDgjNgu30pTOxjQIOnnzSoCn/n0QjWA
9
- O9JcMyO2kI6+dNJnWBfs7BhCz4fPJA6IfU57vaq50sSH99/DEbc7SDJh+Ty1z4iW
10
- dX/4h+6GNtIUqBh35+fz606tN1x+RSET+/oDAHI78+KB8AkC4rTmdIBRAgMBAAGj
11
- QjBAMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFJ8n4kEQjFyA504p+iJj2zr7
12
- vpiPMA4GA1UdDwEB/wQEAwIChDANBgkqhkiG9w0BAQsFAAOCAQEAGHMjDFX1myDL
13
- eHqlwxQTYJk1+sc68rfUxB70a/MU5OMZ8z53YTDbkeOhlsmrIuDMhIt3ZVHizWka
14
- nITpKzU7cuRLJEyozps2bZyX/8QaoKwTkqV5IUV4W9FoL8K8A/zTOKp2H/T8WiSu
15
- 5b29cltqXYrsWj2La3Fm0uaqupfweZgwLN/z/wRg+k7ZzAaHdAehZ9DW2mUkgqHg
16
- 5z6f4SOvTvyTAcphG4tqeFk4YjV4OQcBSuDsnLxs1mQpQ12eA2gmoRQ3W70zRtdI
17
- 1UzqunyLrz5Pt59fitaSeXfthfFNKW67zSfGfJhoqngIuxG/+UaAaDRx/LBJjO0O
18
- 4/ztS0AZ/A==
19
- -----END CERTIFICATE-----
package/nest-cli.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/nest-cli",
3
- "collection": "@nestjs/schematics",
4
- "sourceRoot": "src",
5
- "compilerOptions": {
6
- "deleteOutDir": true
7
- }
8
- }
@@ -1,62 +0,0 @@
1
- import { GoneException, Logger, NotFoundException } from '@nestjs/common';
2
- import { FilterQuery, HydratedDocument, Model, PopulateOptions } from 'mongoose';
3
- import { AbstractEntity } from './abstract.entity';
4
- import { FindResult, FindValidator, ReadValidator } from './abstract.validator';
5
-
6
- export abstract class AbstractRepository<E extends AbstractEntity = AbstractEntity> {
7
- protected abstract $model: Model<AbstractEntity>;
8
-
9
- public find(validator: FindValidator<E> = {}, ...params: unknown[]): Promise<FindResult<E>> {
10
- const filters: FilterQuery<E> = { deletedAt: null, ...validator.filters };
11
-
12
- const query = this.$model.find<E>(filters);
13
- const counter = this.$model.count(filters);
14
-
15
- const skip = validator.page * validator.limit - validator.limit;
16
-
17
- !validator.sort?.createdAt && (validator.sort = { ...validator.sort, createdAt: 'desc' });
18
-
19
- validator.page && query.skip(skip);
20
- validator.sort && query.sort(validator.sort);
21
-
22
- validator.join && query.populate(validator.join as (PopulateOptions | string)[]);
23
-
24
- validator.limit && query.limit(validator.limit);
25
-
26
- return Promise.all([counter.count(), query.exec()]).then(([total, items]) => ({
27
- items,
28
- page: validator.page,
29
- total,
30
- }));
31
- }
32
-
33
- public async read(id: string, validator?: ReadValidator) {
34
- const entity = await this.$model.findById<HydratedDocument<E>>(id);
35
-
36
- if (!entity) {
37
- throw new NotFoundException();
38
- }
39
-
40
- if (entity.deletedAt) {
41
- throw new GoneException();
42
- }
43
-
44
- if (validator?.join) {
45
- await entity
46
- .populate(validator.join as [])
47
- .catch(() => Logger.warn(`Issue populating fields with id: ${entity._id}`));
48
- }
49
-
50
- return entity;
51
- }
52
-
53
- public abstract create(validator: unknown, ...params: unknown[]): any;
54
-
55
- public abstract update(id: string, validator: unknown): any;
56
-
57
- public async delete(id: string) {
58
- await this.read(id);
59
-
60
- return this.$model.deleteOne({ _id: id });
61
- }
62
- }
@@ -1,18 +0,0 @@
1
- import { AbstractRepository } from './abstarct.repository';
2
- import { IdMongoValidator, ReadValidator } from './abstract.validator';
3
-
4
- export abstract class AbstractController {
5
- protected abstract readonly $repository: AbstractRepository;
6
-
7
- protected find?(...params: unknown[]) {
8
- return this.$repository.find();
9
- }
10
-
11
- protected read?({ id }: IdMongoValidator, validator?: ReadValidator) {
12
- return this.$repository.read(id, validator);
13
- }
14
-
15
- protected delete?({ id }: IdMongoValidator) {
16
- return this.$repository.delete(id);
17
- }
18
- }
@@ -1,22 +0,0 @@
1
- import { Prop } from '@nestjs/mongoose';
2
- import { Schema as MongoSchema } from 'mongoose';
3
-
4
- export const $collection = {
5
- timestamps: true,
6
- toJSON: { versionKey: false, virtuals: true },
7
- };
8
-
9
- export type MaybeEntity<T extends AbstractEntity> = T;
10
-
11
- export abstract class AbstractEntity {
12
- public readonly _id = String();
13
-
14
- @Prop({ type: MongoSchema.Types.Date })
15
- public readonly createdAt: Date;
16
-
17
- @Prop({ type: MongoSchema.Types.Date })
18
- public readonly updatedAt?: Date = null;
19
-
20
- @Prop({ default: null, type: MongoSchema.Types.Date })
21
- public readonly deletedAt?: Date = null;
22
- }
@@ -1,7 +0,0 @@
1
- export abstract class AbstractRouter {
2
- public static readonly path: string;
3
-
4
- public static readonly module: typeof AbstractRouter;
5
-
6
- public static readonly children? = [];
7
- }
@@ -1,61 +0,0 @@
1
- import { Transform } from 'class-transformer';
2
- import { IsInt, IsMongoId, isObject, IsOptional } from 'class-validator';
3
- import { FilterQuery, PopulateOptions, SortOrder } from 'mongoose';
4
- import { AbstractEntity } from './abstract.entity';
5
-
6
- export abstract class AbstractValidator {}
7
-
8
- export type FindResult<I> = { items: I[]; page: number; total: number };
9
-
10
- export type KeyOfType<T, V> = keyof {
11
- [P in keyof T as T[P] extends V ? P : string]: any;
12
- };
13
-
14
- export class IdMongoValidator {
15
- @IsMongoId()
16
- public id: string;
17
- }
18
-
19
- export class ReadValidator<E = AbstractEntity> extends AbstractValidator {
20
- @Transform(({ value }) => {
21
- try {
22
- return JSON.parse(value);
23
- } catch (e: unknown) {
24
- return value;
25
- }
26
- })
27
- @IsOptional()
28
- public join?: (PopulateOptions | KeyOfType<E, AbstractEntity | AbstractEntity[]>)[] = [];
29
- }
30
-
31
- export class FindValidator<E = AbstractEntity> extends ReadValidator<E> {
32
- @Transform(({ value }) => (value ? Number(value) : 10))
33
- @IsInt()
34
- @IsOptional()
35
- public limit? = 10;
36
-
37
- @Transform(({ value }) => (value ? Number(value) : 1))
38
- @IsInt()
39
- @IsOptional()
40
- public page? = 1;
41
-
42
- @Transform(({ value }) => {
43
- if (isObject(value)) {
44
- return value;
45
- }
46
-
47
- return value && JSON.parse(value);
48
- })
49
- @IsOptional()
50
- public sort?: Partial<Record<keyof E, SortOrder>> = {};
51
-
52
- @Transform(({ value }) => {
53
- if (isObject(value)) {
54
- return value;
55
- }
56
-
57
- return value && JSON.parse(value);
58
- })
59
- @IsOptional()
60
- public filters?: FilterQuery<E> = {};
61
- }
package/src/app.config.ts DELETED
@@ -1,59 +0,0 @@
1
- import { config } from 'dotenv';
2
- import { readFileSync } from 'fs';
3
- import { join } from 'path';
4
- import * as process from 'process';
5
-
6
- config();
7
-
8
- export abstract class AppConfig {
9
- public static get SENTRY() {
10
- return {
11
- dsn: process.env.SENTRY_DSN,
12
- debug: process.env.NODE_ENV !== 'production',
13
- environment: process.env.NODE_ENV,
14
- };
15
- }
16
-
17
- public static get SERVER() {
18
- return {
19
- description: String(process.env.npm_package_description),
20
- isDEV: process.env.NODE_ENV !== 'production',
21
- name: String(process.env.npm_package_name),
22
- port: Number(process.env.PORT || 6500),
23
- version: String(process.env.npm_package_version),
24
- };
25
- }
26
-
27
- public static get MONGO() {
28
- const { MONGO_PASSWORD, MONGO_USER, MONGO_HOST } = process.env;
29
-
30
- return {
31
- host: MONGO_HOST,
32
- user: MONGO_USER,
33
- pass: MONGO_PASSWORD,
34
- retryWrites: true,
35
- w: 'majority',
36
- };
37
- }
38
-
39
- public static get STORAGE() {
40
- const serviceAccount = readFileSync(join(process.cwd(), '/serviceAccount.json'));
41
- const credentials = JSON.parse(serviceAccount.toString());
42
-
43
- return {
44
- projectId: 'api-merkaly-io',
45
- bucketName: process.env.GCP_BUCKET_NAME,
46
- serviceAccount: credentials,
47
- };
48
- }
49
-
50
- public static get AUTH0() {
51
- const domain = 'merkaly.us.auth0.com';
52
- const audience = `https://${domain}/api/v2/`;
53
- const client = 'eApUjfHoWlMPcTUuU1lqvE517q0KzTh9';
54
- const secret = String(process.env.AUTH0_CLIENT_SECRET);
55
- const certificate = process.env.AUTH_CERTIFICATE || readFileSync(join(process.cwd(), '/authCertificate.pem'));
56
-
57
- return { domain, audience, client, secret, certificate };
58
- }
59
- }
@@ -1,24 +0,0 @@
1
- import { BootstrapConsole } from 'nestjs-console';
2
- import process from 'process';
3
- import { AppModule } from './app.module';
4
-
5
- const bootstrap = new BootstrapConsole({
6
- module: AppModule,
7
- useDecorators: true,
8
- });
9
-
10
- bootstrap.init().then(async (app) => {
11
- try {
12
- await app.init();
13
-
14
- await bootstrap.boot();
15
-
16
- await app.close();
17
- } catch (e) {
18
- console.error(e);
19
-
20
- await app.close();
21
-
22
- process.exit(1);
23
- }
24
- });
package/src/app.guard.ts DELETED
@@ -1,39 +0,0 @@
1
- import { ExecutionContext, Inject, Injectable, UnauthorizedException } from '@nestjs/common';
2
- import { Reflector } from '@nestjs/core';
3
- import { AuthGuard as JwtGuard } from '@nestjs/passport';
4
- import { IS_PUBLIC_KEY } from './decorators/public.decorator';
5
- import { DecodedUser } from './decorators/user.decorator';
6
-
7
- declare module 'express' {
8
- interface Request {
9
- user?: DecodedUser;
10
- }
11
- }
12
-
13
- @Injectable()
14
- export class AuthGuard extends JwtGuard('jwt') {
15
- public isPublic = false;
16
- @Inject()
17
- private reflector: Reflector;
18
-
19
- public async canActivate(context: ExecutionContext): Promise<any> {
20
- this.isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
21
- context.getHandler(),
22
- context.getClass(),
23
- ]);
24
-
25
- return super.canActivate(context);
26
- }
27
-
28
- public handleRequest(err: Record<string, unknown>, user: DecodedUser): any {
29
- if (err) {
30
- throw err;
31
- }
32
-
33
- if (!user && !this.isPublic) {
34
- throw new UnauthorizedException();
35
- }
36
-
37
- return user || undefined;
38
- }
39
- }
package/src/app.module.ts DELETED
@@ -1,54 +0,0 @@
1
- import { MiddlewareConsumer, Module, NestModule, RequestMethod, Scope } from '@nestjs/common';
2
- import { ConfigModule } from '@nestjs/config';
3
- import { APP_GUARD, APP_INTERCEPTOR, RouterModule, Routes } from '@nestjs/core';
4
- import { JwtModule } from '@nestjs/jwt';
5
- import { PassportModule } from '@nestjs/passport';
6
- import { ConsoleModule } from 'nestjs-console';
7
- import { AuthGuard } from './app.guard';
8
- import { AppStrategy } from './app.strategy';
9
- import { MongoInterceptor } from './interceptors/mongoose.interceptor';
10
- import { RouterMiddleware } from './middlewares/router.middleware';
11
- import { AssetModule } from './modules/asset/asset.module';
12
- import { AuthModule } from './modules/auth/auth.module';
13
- import { CommandsModule } from './modules/command.module';
14
- import { GlobalModule } from './modules/global.module';
15
- import { InventoryModule } from './modules/inventory/inventory.module';
16
- import { SaleModule } from './modules/sale/sale.module';
17
-
18
- export const router = [AuthModule, AssetModule, ConfigModule, InventoryModule, SaleModule];
19
-
20
- @Module({
21
- controllers: [],
22
- imports: [
23
- ...router,
24
- GlobalModule.register(),
25
- RouterModule.register(router as Routes),
26
- JwtModule.register({ global: true, signOptions: { expiresIn: '60s' } }),
27
- ConfigModule.forRoot({ isGlobal: true }),
28
- PassportModule,
29
- ConsoleModule,
30
- CommandsModule.register(),
31
- ],
32
- providers: [
33
- AppStrategy,
34
- {
35
- provide: APP_GUARD,
36
- useClass: AuthGuard,
37
- },
38
- {
39
- provide: APP_INTERCEPTOR,
40
- scope: Scope.REQUEST,
41
- useClass: MongoInterceptor,
42
- },
43
- ],
44
- })
45
- export class AppModule implements NestModule {
46
- public configure(consumer: MiddlewareConsumer) {
47
- consumer
48
- .apply(RouterMiddleware)
49
- .exclude({ path: '/auth/resolve', method: RequestMethod.GET })
50
- .forRoutes({ path: '/*', method: RequestMethod.ALL });
51
-
52
- return consumer;
53
- }
54
- }
@@ -1,21 +0,0 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { PassportStrategy } from '@nestjs/passport';
3
- import { ExtractJwt, Strategy, StrategyOptions } from 'passport-jwt';
4
- import { AppConfig } from './app.config';
5
- import { DecodedUser } from './decorators/user.decorator';
6
-
7
- @Injectable()
8
- export class AppStrategy extends PassportStrategy(Strategy) {
9
- public constructor() {
10
- const strategy: StrategyOptions = {
11
- jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
12
- secretOrKey: AppConfig.AUTH0.certificate,
13
- };
14
-
15
- super(strategy);
16
- }
17
-
18
- public validate(user: DecodedUser) {
19
- return user;
20
- }
21
- }
@@ -1,263 +0,0 @@
1
- import { faker } from '@faker-js/faker/locale/pt_BR';
2
- import { Inject } from '@nestjs/common';
3
- import { InjectConnection } from '@nestjs/mongoose';
4
- import { Connection } from 'mongoose';
5
- import { Command, Console } from 'nestjs-console';
6
- import process from 'process';
7
- import { FileRepository } from '../modules/asset/files/file.repository';
8
- import { FileSchema } from '../modules/asset/files/file.schema';
9
- import { UserRepository } from '../modules/auth/users/user.repository';
10
- import { UserSchema } from '../modules/auth/users/user.schema';
11
- import { CreateUserValidator } from '../modules/auth/users/user.validator';
12
- import { BrandSchema } from '../modules/inventory/brands/brand.schema';
13
- import { CategoryRepository } from '../modules/inventory/categories/category.repository';
14
- import { CategorySchema } from '../modules/inventory/categories/category.schema';
15
- import { CreateCategoryValidator } from '../modules/inventory/categories/category.validator';
16
- import { ProductRepository } from '../modules/inventory/products/product.repository';
17
- import { ProductSchema } from '../modules/inventory/products/product.schema';
18
- import { CreateProductValidator } from '../modules/inventory/products/product.validator';
19
- import { OrderStatus } from '../modules/sale/orders/enums/order.status';
20
- import { OrderRepository } from '../modules/sale/orders/order.repository';
21
- import { CreateOrderValidator } from '../modules/sale/orders/order.validator';
22
- import { BillingType } from '../modules/sale/payments/enums/billing.type';
23
- import { PaymentStatus } from '../modules/sale/payments/enums/payment.status';
24
- import { ShippingType } from '../modules/sale/payments/enums/shipping.type';
25
-
26
- @Console({ command: 'seed' })
27
- export class SeedCommand {
28
- @Inject()
29
- protected readonly $productRepository: ProductRepository;
30
-
31
- @Inject()
32
- protected readonly $categoryRepository: CategoryRepository;
33
-
34
- @Inject()
35
- protected readonly $userRepository: UserRepository;
36
-
37
- @Inject()
38
- protected readonly $orderRepository: OrderRepository;
39
-
40
- @Inject()
41
- protected readonly $usersRepository: UserRepository;
42
-
43
- @Inject()
44
- protected readonly $categoriesRepository: CategoryRepository;
45
-
46
- @Inject()
47
- protected readonly $filesRepository: FileRepository;
48
-
49
- @InjectConnection()
50
- private connection: Connection;
51
-
52
- @Command({ command: 'app', description: 'Seed entire app with random data' })
53
- public async seedEntireApp() {
54
- const list = [];
55
-
56
- list.push(
57
- this.connection.collection(ProductSchema.name).deleteMany(),
58
- this.connection.collection(CategorySchema.name).deleteMany(),
59
- this.connection.collection(BrandSchema.name).deleteMany(),
60
-
61
- this.connection.collection(FileSchema.name).deleteMany(),
62
- this.connection.collection(UserSchema.name).deleteMany(),
63
- );
64
-
65
- await Promise.all(list);
66
-
67
- await this.generateUser();
68
- await this.generateCategories();
69
- await this.generateProducts();
70
- await this.generateOrders();
71
-
72
- return process?.exit?.(1);
73
- }
74
-
75
- @Command({ command: 'categories <counter>', description: 'Generate random categories' })
76
- public async generateCategories(counter = 10) {
77
- return this.generate(() => {
78
- const category = new CreateCategoryValidator();
79
- category.name = faker.lorem.words(2).concat(faker.helpers.replaceSymbols('********'));
80
- category.description = faker.lorem.sentence();
81
-
82
- return this.$categoryRepository.create(category);
83
- }, counter);
84
- }
85
-
86
- @Command({ command: 'products <counter>', description: 'Generate random products' })
87
- public async generateProducts(counter = 50) {
88
- const { items: categories } = await this.$categoriesRepository.find();
89
-
90
- await this.generate(async () => {
91
- const validator = new CreateProductValidator();
92
-
93
- validator.active = faker.datatype.boolean({ probability: 0.9 });
94
- validator.name = `${faker.commerce.productName()} ${faker.helpers.replaceSymbols('*****')}`;
95
- validator.description = faker.lorem.lines({ max: 6, min: 3 });
96
- validator.price = Math.round(Math.random() * 100_000);
97
-
98
- validator.attributes.units = faker.helpers.arrayElement([1, 5, 10]);
99
- validator.attributes.sku = faker.helpers.replaceSymbols('*******');
100
- validator.attributes.stock = faker.number.int({ min: 0, max: 100 });
101
-
102
- if (faker.datatype.boolean({ probability: 0.9 })) {
103
- validator.category = faker.helpers.arrayElement(categories)._id;
104
- }
105
-
106
- if (faker.datatype.boolean({ probability: 0.8 })) {
107
- const files = await this.generate(() => {
108
- const url = `https://cartzilla.createx.studio/img/shop/catalog/${faker.number
109
- .int({ max: 72, min: 1 })
110
- .toString()
111
- .padStart(2, '0')}.jpg`;
112
-
113
- return this.$filesRepository.create({
114
- description: faker.lorem.sentence(),
115
- name: faker.helpers.replaceSymbols('********.jpg'),
116
- size: faker.number.int(),
117
- type: faker.system.mimeType(),
118
- url: url,
119
- weak: false,
120
- });
121
- }, faker.number.int({ max: 5, min: 0 }));
122
-
123
- validator.pictures = files.map(({ _id }) => _id);
124
- }
125
-
126
- return this.$productRepository.create(validator);
127
- }, counter);
128
- }
129
-
130
- @Command({ command: 'users <counter>', description: 'Generate random users' })
131
- public async generateUser(counter = 50) {
132
- return this.generate(() => {
133
- const user = new CreateUserValidator();
134
-
135
- user.auth0 = faker.database.mongodbObjectId();
136
- user.name = faker.person.fullName();
137
- user.email = faker.internet.email({ lastName: user.name });
138
- user.picture = faker.internet.avatar();
139
- user.locale = faker.helpers.arrayElement(['es', 'pt', 'en']);
140
-
141
- return this.$userRepository.create(user);
142
- }, counter);
143
- }
144
-
145
- @Command({ command: 'orders <counter>', description: 'Generate random users' })
146
- public async generateOrders(counter = 300) {
147
- const { items: users } = await this.$userRepository.find();
148
- const { items: products } = await this.$productRepository.find();
149
-
150
- return this.generate(async () => {
151
- const order = new CreateOrderValidator();
152
- order.description = faker.lorem.sentence();
153
-
154
- order.billing.type = faker.helpers.enumValue(BillingType);
155
- order.billing.address = {
156
- city: faker.location.city(),
157
- code: faker.location.zipCode(),
158
- country: faker.location.countryCode('alpha-2'),
159
- line1: `${faker.location.buildingNumber()} ${faker.location.street()}`,
160
- line2: faker.location.secondaryAddress(),
161
- state: faker.location.state(),
162
- };
163
-
164
- order.shipping.type = faker.helpers.enumValue(ShippingType);
165
- order.shipping.email = faker.internet.email();
166
- order.shipping.phone = faker.phone.number();
167
- order.shipping.name = faker.person.fullName();
168
- order.shipping.address = {
169
- city: faker.location.city(),
170
- code: faker.location.zipCode(),
171
- country: faker.location.countryCode('alpha-2'),
172
- line1: `${faker.location.buildingNumber()} ${faker.location.street()}`,
173
- line2: faker.location.secondaryAddress(),
174
- state: faker.location.state(),
175
- };
176
-
177
- const items = faker.number.int({ max: 10, min: 1 });
178
-
179
- order.items = [...Array(items)].map(() => ({
180
- product: faker.helpers.arrayElement(products)._id,
181
- quantity: Number(faker.number.int({ max: 10, min: 1 })),
182
- }));
183
-
184
- const randomUser = faker.helpers.arrayElement(users);
185
-
186
- const createdOrder = await this.$orderRepository.create(order, randomUser);
187
-
188
- const generateStatus = (state: OrderStatus) => {
189
- const lastDate = faker.date.past({
190
- refDate: createdOrder.status[createdOrder.status.length - 1]?.date,
191
- years: 1,
192
- });
193
-
194
- return createdOrder.status.push({
195
- date: lastDate,
196
- name: state,
197
- user: randomUser._id as any,
198
- });
199
- };
200
-
201
- const generatePayment = (state: PaymentStatus) => {
202
- const lastDate = faker.date.past({
203
- refDate: createdOrder.status[createdOrder.status.length - 1]?.date,
204
- years: 1,
205
- });
206
-
207
- if (typeof createdOrder.payment === 'string') {
208
- return createdOrder;
209
- }
210
-
211
- return createdOrder.payment.status.push({
212
- date: lastDate,
213
- name: state,
214
- user: randomUser._id as any,
215
- });
216
- };
217
-
218
- faker.helpers.maybe(() => generateStatus(OrderStatus.ACCEPTED), {
219
- probability: 0.9,
220
- });
221
- faker.helpers.maybe(() => generateStatus(OrderStatus.COMPLETED), {
222
- probability: 0.6,
223
- });
224
- faker.helpers.maybe(() => generateStatus(OrderStatus.CANCELED), {
225
- probability: 0.3,
226
- });
227
-
228
- faker.helpers.maybe(() => generatePayment(PaymentStatus.WAITING), {
229
- probability: 0.8,
230
- });
231
- faker.helpers.maybe(() => generatePayment(PaymentStatus.PAID), {
232
- probability: 0.6,
233
- });
234
- faker.helpers.maybe(() => generatePayment(PaymentStatus.CANCELLED), {
235
- probability: 0.4,
236
- });
237
- faker.helpers.maybe(() => generatePayment(PaymentStatus.REFUNDED), {
238
- probability: 0.2,
239
- });
240
-
241
- await createdOrder.updateOne({
242
- $set: { createdAt: faker.date.past({ years: 3 }) },
243
- });
244
-
245
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
246
- // @ts-ignore
247
- await createdOrder.payment.save();
248
- await createdOrder.save();
249
-
250
- return createdOrder;
251
- }, counter);
252
- }
253
-
254
- private generate<T = unknown>(hook: (index: number) => Promise<T>, lenght: number) {
255
- const listOfPromises: Promise<T>[] = [];
256
-
257
- for (let iterator = 0; iterator < Number(lenght); iterator++) {
258
- listOfPromises.push(hook(iterator));
259
- }
260
-
261
- return Promise.all(listOfPromises);
262
- }
263
- }