@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
@@ -1,62 +0,0 @@
1
- import { Body, Controller, Delete, Get, Inject, Param, Patch, Post, Query } from '@nestjs/common';
2
- import { ApiTags } from '@nestjs/swagger';
3
- import { AbstractController } from '../../../abstracts/abstract.controller';
4
- import { FindValidator, IdMongoValidator, ReadValidator } from '../../../abstracts/abstract.validator';
5
- import { Public } from '../../../decorators/public.decorator';
6
- import { ProductEntity } from './product.entity';
7
- import { ProductRepository } from './product.repository';
8
- import { CreateProductValidator, UpdateProductValidator } from './product.validator';
9
-
10
- @Controller('/')
11
- @ApiTags('inventory')
12
- export class ProductController extends AbstractController {
13
- @Inject()
14
- protected readonly $repository: ProductRepository;
15
-
16
- @Public()
17
- @Get('/')
18
- public find(@Query() validator: FindValidator<ProductEntity>) {
19
- return this.$repository.find(validator);
20
- }
21
-
22
- @Public()
23
- @Post('/')
24
- public create(@Body() validator: CreateProductValidator) {
25
- return this.$repository.create(validator);
26
- }
27
-
28
- @Public()
29
- @Get('/:id')
30
- public read(@Param() { id }: IdMongoValidator, @Query() validator?: ReadValidator) {
31
- return this.$repository.read(id, validator);
32
- }
33
-
34
- @Patch('/:id')
35
- public update(@Param() { id }: IdMongoValidator, @Body() validator: UpdateProductValidator) {
36
- return this.$repository.update(id, validator);
37
- }
38
-
39
- @Delete('/:id')
40
- public delete(@Param() { id }: IdMongoValidator) {
41
- return this.$repository.delete(id);
42
- }
43
-
44
- @Public()
45
- @Get('/:id/related')
46
- public async findRelated(@Param() { id }: IdMongoValidator, @Query() validator: FindValidator<ProductEntity> = {}) {
47
- const product = await this.read({ id }, {});
48
-
49
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
50
- // @ts-ignore
51
- validator.filters._id = { $ne: id };
52
- validator.filters.category = product.category;
53
- validator.filters.$text = {
54
- $caseSensitive: false,
55
- $search: product.name,
56
- };
57
-
58
- const { items } = await this.$repository.find(validator);
59
-
60
- return items;
61
- }
62
- }
@@ -1,46 +0,0 @@
1
- import { Prop, Schema as Collection } from '@nestjs/mongoose';
2
- import { Schema } from 'mongoose';
3
- import { $collection, AbstractEntity, MaybeEntity } from '../../../abstracts/abstract.entity';
4
- import { FileEntity } from '../../asset/files/file.entity';
5
- import { FileSchema } from '../../asset/files/file.schema';
6
- import { BrandEntity } from '../brands/brand.entity';
7
- import { BrandSchema } from '../brands/brand.schema';
8
- import { CategoryEntity } from '../categories/category.entity';
9
- import { CategorySchema } from '../categories/category.schema';
10
- import { ProductAttributesDocument } from './documents/attribute.document';
11
- import { ProductDimensionDocument } from './documents/dimension.document';
12
-
13
- @Collection($collection)
14
- export class ProductEntity extends AbstractEntity {
15
- @Prop({ required: true, type: Schema.Types.String, unique: true })
16
- public name: string;
17
-
18
- @Prop({ default: () => String(), type: Schema.Types.String })
19
- public description: string;
20
-
21
- @Prop({ default: true, type: Schema.Types.Boolean })
22
- public active = true;
23
-
24
- @Prop({ required: true, type: Schema.Types.Number })
25
- public price: number;
26
-
27
- @Prop({ default: [], type: Schema.Types.Array })
28
- public hashtags: string[] = [];
29
-
30
- @Prop({ ref: BrandSchema.name, type: Schema.Types.ObjectId })
31
- public brand?: MaybeEntity<BrandEntity>;
32
-
33
- @Prop({ ref: CategorySchema.name, type: Schema.Types.ObjectId })
34
- public category?: MaybeEntity<CategoryEntity>;
35
-
36
- @Prop({ default: [], ref: FileSchema.name, type: [{ type: Schema.Types.String }] })
37
- public pictures: FileEntity[] = [];
38
-
39
- @Prop({ default: () => new ProductAttributesDocument(), type: Schema.Types.Mixed })
40
- public attributes = new ProductAttributesDocument();
41
-
42
- @Prop({ default: () => new ProductDimensionDocument(), type: Schema.Types.Mixed })
43
- public dimension = new ProductDimensionDocument();
44
-
45
- public readonly image: string;
46
- }
@@ -1,19 +0,0 @@
1
- import { Module, ModuleMetadata } from '@nestjs/common';
2
- import { ProductController } from './product.controller';
3
- import { ProductRepository } from './product.repository';
4
-
5
- export const metadata: ModuleMetadata = {
6
- controllers: [ProductController],
7
- exports: [ProductRepository],
8
- imports: [],
9
- providers: [ProductRepository],
10
- };
11
-
12
- @Module(metadata)
13
- export class ProductModule {
14
- public static readonly path = '/products';
15
-
16
- public static readonly module = ProductModule;
17
-
18
- public static readonly children = metadata.imports;
19
- }
@@ -1,64 +0,0 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { InjectModel } from '@nestjs/mongoose';
3
- import { Model } from 'mongoose';
4
- import { AbstractRepository } from '../../../abstracts/abstarct.repository';
5
- import { ProductEntity } from './product.entity';
6
- import { ProductSchema } from './product.schema';
7
- import { CreateProductValidator, UpdateProductValidator } from './product.validator';
8
-
9
- @Injectable()
10
- export class ProductRepository extends AbstractRepository<ProductEntity> {
11
- @InjectModel(ProductSchema.name)
12
- protected readonly $model: Model<ProductEntity>;
13
-
14
- public async create(validator: CreateProductValidator) {
15
- const product = new this.$model();
16
-
17
- product.active = validator.active;
18
-
19
- product.name = validator.name;
20
- product.description = validator.description;
21
- product.price = validator.price;
22
- product.hashtags = validator.hashtags;
23
-
24
- product.pictures = validator.pictures as any;
25
- product.category = validator.category as any;
26
- product.brand = validator.brand as any;
27
-
28
- product.dimension = {
29
- depth: validator.dimension?.depth,
30
- height: validator.dimension?.height,
31
- weight: validator.dimension?.weight,
32
- width: validator.dimension?.width,
33
- };
34
-
35
- product.attributes = {
36
- stock: validator.attributes.stock,
37
- sku: validator.attributes.sku,
38
- units: validator.attributes.units,
39
- };
40
-
41
- await product.save();
42
-
43
- return product;
44
- }
45
-
46
- public async update(id: string, validator: UpdateProductValidator) {
47
- const product = await this.read(id);
48
-
49
- validator.active && (product.active = validator.active);
50
-
51
- validator.name && (product.name = validator.name);
52
- validator.description && (product.description = validator.description);
53
- validator.price && (product.price = validator.price);
54
- validator.hashtags?.length && (product.hashtags = validator.hashtags);
55
-
56
- validator.category && (product.category = validator.category as any);
57
- validator.brand && (product.brand = validator.brand as any);
58
- validator.pictures?.length && (product.pictures = validator.pictures as any);
59
-
60
- await product.save();
61
-
62
- return product;
63
- }
64
- }
@@ -1,19 +0,0 @@
1
- import { SchemaFactory } from '@nestjs/mongoose';
2
- import { ProductEntity } from './product.entity';
3
-
4
- export namespace ProductSchema {
5
- export const name = 'inventory_products';
6
-
7
- export const schema = SchemaFactory.createForClass(ProductEntity);
8
-
9
- schema.index({
10
- description: 'text',
11
- name: 'text',
12
- });
13
-
14
- schema.virtual('image').get(function () {
15
- const [first] = this.pictures;
16
-
17
- return first?.url;
18
- });
19
- }
@@ -1,132 +0,0 @@
1
- import { Type } from 'class-transformer';
2
- import {
3
- IsArray,
4
- IsBoolean,
5
- IsMongoId,
6
- IsNotEmpty,
7
- IsNumber,
8
- IsOptional,
9
- IsPositive,
10
- IsString,
11
- ValidateNested,
12
- } from 'class-validator';
13
- import { AbstractValidator } from '../../../abstracts/abstract.validator';
14
- import { ProductEntity } from './product.entity';
15
- import { AttributesValidator } from './validators/attributes.validator';
16
- import { DimensionValidator } from './validators/dimension.validator';
17
-
18
- export class CreateProductValidator extends AbstractValidator {
19
- @IsBoolean()
20
- @IsOptional()
21
- public active? = true;
22
-
23
- @IsString({ each: true })
24
- @IsNotEmpty({ each: true })
25
- @IsOptional()
26
- public hashtags?: string[] = [];
27
-
28
- @IsString()
29
- @IsNotEmpty()
30
- public name: string;
31
-
32
- @IsString()
33
- @IsOptional()
34
- public description: string;
35
-
36
- @IsNumber()
37
- @IsPositive()
38
- public price: number;
39
-
40
- @IsMongoId({ each: true })
41
- @IsArray()
42
- @IsOptional()
43
- public pictures?: string[] = [];
44
-
45
- @IsOptional()
46
- @IsMongoId()
47
- public category?: string;
48
-
49
- @IsOptional()
50
- @IsMongoId()
51
- public brand?: string;
52
-
53
- @Type(() => DimensionValidator)
54
- @ValidateNested()
55
- @IsOptional()
56
- public dimension? = new DimensionValidator();
57
-
58
- @Type(() => AttributesValidator)
59
- @ValidateNested()
60
- @IsOptional()
61
- public attributes? = new AttributesValidator();
62
- }
63
-
64
- export class UpdateProductValidator {
65
- @IsBoolean()
66
- @IsOptional()
67
- public active?: boolean;
68
-
69
- @IsString({ each: true })
70
- @IsNotEmpty({ each: true })
71
- @IsOptional()
72
- public hashtags?: string[] = [];
73
-
74
- @IsOptional()
75
- @IsString()
76
- @IsNotEmpty()
77
- public name?: string;
78
-
79
- @IsOptional()
80
- @IsString()
81
- @IsOptional()
82
- public description?: string;
83
-
84
- @IsOptional()
85
- @IsNumber()
86
- public price?: number;
87
-
88
- @IsOptional()
89
- @IsMongoId()
90
- public category?: string;
91
-
92
- @IsOptional()
93
- @IsMongoId()
94
- public brand?: string;
95
-
96
- @IsMongoId({ each: true })
97
- @IsArray()
98
- @IsOptional()
99
- public pictures?: string[] = [];
100
-
101
- @Type(() => DimensionValidator)
102
- @ValidateNested()
103
- @IsOptional()
104
- public dimension?: DimensionValidator;
105
-
106
- @Type(() => AttributesValidator)
107
- @ValidateNested()
108
- @IsOptional()
109
- public attributes?: AttributesValidator = new AttributesValidator();
110
-
111
- public constructor(entity: ProductEntity) {
112
- this.active = entity.active;
113
-
114
- this.name = entity.name;
115
- this.description = entity.description;
116
- this.price = entity.price;
117
- this.hashtags = entity.hashtags;
118
-
119
- this.category = entity.category?._id;
120
- this.brand = entity.brand?._id;
121
- this.pictures = entity.pictures.map((file) => file._id);
122
-
123
- this.attributes.sku = entity.attributes.sku;
124
- this.attributes.stock = entity.attributes.stock;
125
- this.attributes.units = entity.attributes.units;
126
-
127
- this.dimension.depth = entity.dimension.depth;
128
- this.dimension.height = entity.dimension.height;
129
- this.dimension.weight = entity.dimension.weight;
130
- this.dimension.width = entity.dimension.width;
131
- }
132
- }
@@ -1,15 +0,0 @@
1
- import { IsNumber, IsOptional, IsPositive, IsString } from 'class-validator';
2
-
3
- export class AttributesValidator {
4
- @IsPositive()
5
- public units = 1;
6
-
7
- @IsNumber()
8
- @IsOptional()
9
- public stock: number | null = null;
10
-
11
- @IsString()
12
- @IsOptional()
13
- @IsOptional()
14
- public sku: string;
15
- }
@@ -1,19 +0,0 @@
1
- import { IsOptional, IsPositive } from 'class-validator';
2
-
3
- export class DimensionValidator {
4
- @IsPositive()
5
- @IsOptional()
6
- public weight: number;
7
-
8
- @IsPositive()
9
- @IsOptional()
10
- public height: number;
11
-
12
- @IsPositive()
13
- @IsOptional()
14
- public width: number;
15
-
16
- @IsPositive()
17
- @IsOptional()
18
- public depth: number;
19
- }
@@ -1,41 +0,0 @@
1
- import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Inject, Param, Patch, Post, Query } from '@nestjs/common';
2
- import { ApiTags } from '@nestjs/swagger';
3
- import { AbstractController } from '../../../abstracts/abstract.controller';
4
- import { FindValidator, IdMongoValidator, ReadValidator } from '../../../abstracts/abstract.validator';
5
- import { CustomerEntity } from './customer.entity';
6
- import { CustomerRepository } from './customer.repository';
7
- import { CreateCustomerValidator, UpdateCustomerValidator } from './customer.validator';
8
-
9
- @Controller()
10
- @ApiTags('sale')
11
- export class CustomerController extends AbstractController {
12
- @Inject()
13
- protected readonly $repository: CustomerRepository;
14
-
15
- @Get('/')
16
- public async find(@Query() validator: FindValidator<CustomerEntity>) {
17
- return this.$repository.find(validator);
18
- }
19
-
20
- @Get('/:id')
21
- public read(@Param() { id }: IdMongoValidator, @Query() validator?: ReadValidator) {
22
- return this.$repository.read(id, validator);
23
- }
24
-
25
- @Post('/')
26
- @HttpCode(HttpStatus.CREATED)
27
- public async create(@Body() validator: CreateCustomerValidator) {
28
- return this.$repository.create(validator);
29
- }
30
-
31
- @Patch('/:id')
32
- public async update(@Param() { id }: IdMongoValidator, @Body() validator: UpdateCustomerValidator) {
33
- return this.$repository.update(id, validator);
34
- }
35
-
36
- @Delete('/:id')
37
- @HttpCode(HttpStatus.NO_CONTENT)
38
- public delete(@Param() { id }: IdMongoValidator) {
39
- return this.$repository.delete(id);
40
- }
41
- }
@@ -1,19 +0,0 @@
1
- import { Prop, Schema as Collection } from '@nestjs/mongoose';
2
- import { Schema } from 'mongoose';
3
- import { $collection, AbstractEntity } from '../../../abstracts/abstract.entity';
4
- import { AddressValidator } from '../orders/validators/address.validator';
5
-
6
- @Collection($collection)
7
- export class CustomerEntity extends AbstractEntity {
8
- @Prop({ type: Schema.Types.String, required: true })
9
- public name: string;
10
-
11
- @Prop({ type: Schema.Types.String, unique: true, required: true })
12
- public email: string;
13
-
14
- @Prop({ type: Schema.Types.String, default: null })
15
- public phone: string;
16
-
17
- @Prop({ type: Schema.Types.Array, default: [] })
18
- public addresses: AddressValidator[] = [];
19
- }
@@ -1,18 +0,0 @@
1
- import { Module, ModuleMetadata } from '@nestjs/common';
2
- import { AbstractRouter } from '../../../abstracts/abstract.router';
3
- import { CustomerController } from './customer.controller';
4
- import { CustomerRepository } from './customer.repository';
5
-
6
- export const metadata: ModuleMetadata = {
7
- controllers: [CustomerController],
8
- exports: [CustomerRepository],
9
- imports: [],
10
- providers: [CustomerRepository],
11
- };
12
-
13
- @Module(metadata)
14
- export class CustomerModule extends AbstractRouter {
15
- public static readonly path = '/customers';
16
-
17
- public static readonly module = CustomerModule;
18
- }
@@ -1,30 +0,0 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { InjectModel } from '@nestjs/mongoose';
3
- import { Model } from 'mongoose';
4
- import { AbstractRepository } from '../../../abstracts/abstarct.repository';
5
- import { CustomerEntity } from './customer.entity';
6
- import { CustomerSchema } from './customer.schema';
7
- import { CreateCustomerValidator, UpdateCustomerValidator } from './customer.validator';
8
-
9
- @Injectable()
10
- export class CustomerRepository extends AbstractRepository<CustomerEntity> {
11
- @InjectModel(CustomerSchema.name)
12
- public readonly $model: Model<CustomerEntity>;
13
-
14
- public async create(validator: CreateCustomerValidator) {
15
- const customer = new this.$model();
16
-
17
- customer.name = validator.name;
18
- customer.email = validator.email;
19
- customer.phone = validator.phone;
20
- customer.addresses = validator.addresses;
21
-
22
- await customer.save();
23
-
24
- return customer;
25
- }
26
-
27
- public async update(id: string, validator: UpdateCustomerValidator): Promise<CustomerEntity> {
28
- return super.read(id);
29
- }
30
- }
@@ -1,8 +0,0 @@
1
- import { SchemaFactory } from '@nestjs/mongoose';
2
- import { CustomerEntity } from './customer.entity';
3
-
4
- export namespace CustomerSchema {
5
- export const name = 'sale_customers';
6
-
7
- export const schema = SchemaFactory.createForClass(CustomerEntity);
8
- }
@@ -1,43 +0,0 @@
1
- import { Transform, Type } from 'class-transformer';
2
- import { IsArray, IsEmail, IsOptional, IsPhoneNumber, IsString, ValidateNested } from 'class-validator';
3
- import { AbstractValidator } from '../../../abstracts/abstract.validator';
4
- import { AddressValidator } from '../orders/validators/address.validator';
5
-
6
- export class CreateCustomerValidator extends AbstractValidator {
7
- @IsString()
8
- public name: string;
9
-
10
- @IsEmail()
11
- @Transform(({ value }) => String(value).toLowerCase())
12
- public email: string;
13
-
14
- @IsString()
15
- @IsOptional()
16
- public phone?: string;
17
-
18
- @IsArray()
19
- @Type(() => AddressValidator)
20
- @ValidateNested()
21
- public addresses?: AddressValidator[] = [];
22
- }
23
-
24
- export class UpdateCustomerValidator {
25
- @IsString()
26
- @IsOptional()
27
- public name?: string;
28
-
29
- @IsEmail()
30
- @Transform(({ value }) => String(value).toLowerCase())
31
- @IsOptional()
32
- public email?: string;
33
-
34
- @IsPhoneNumber()
35
- @IsOptional()
36
- public phone?: string;
37
-
38
- @IsArray()
39
- @Type(() => AddressValidator)
40
- @ValidateNested()
41
- @IsOptional()
42
- public addresses?: AddressValidator[];
43
- }
@@ -1,22 +0,0 @@
1
- import { Prop } from '@nestjs/mongoose';
2
- import { Schema } from 'mongoose';
3
-
4
- export class AddressDocument {
5
- @Prop({ required: true, type: Schema.Types.String })
6
- public line1: string;
7
-
8
- @Prop({ type: Schema.Types.String })
9
- public line2: string;
10
-
11
- @Prop({ required: true, type: Schema.Types.String })
12
- public state: string;
13
-
14
- @Prop({ required: true, type: Schema.Types.String })
15
- public city: string;
16
-
17
- @Prop({ type: Schema.Types.String })
18
- public country: string;
19
-
20
- @Prop({ required: true, type: Schema.Types.String })
21
- public code: string;
22
- }
@@ -1,17 +0,0 @@
1
- import { Prop } from '@nestjs/mongoose';
2
- import { Schema } from 'mongoose';
3
- import { MaybeEntity } from '../../../../abstracts/abstract.entity';
4
- import { UserEntity } from '../../../auth/users/user.entity';
5
- import { UserSchema } from '../../../auth/users/user.schema';
6
- import { OrderStatus } from '../enums/order.status';
7
-
8
- export class StatusDocument {
9
- @Prop({ default: OrderStatus.CREATED, enum: OrderStatus, required: true, type: Schema.Types.String })
10
- public name: OrderStatus;
11
-
12
- @Prop({ ref: UserSchema.name, required: true, type: Schema.Types.ObjectId })
13
- public user: MaybeEntity<UserEntity>;
14
-
15
- @Prop({ default: () => new Date(), type: Schema.Types.Date })
16
- public date = new Date();
17
- }
@@ -1,24 +0,0 @@
1
- import { Prop, SchemaFactory } from '@nestjs/mongoose';
2
- import { Schema as Collection } from '@nestjs/mongoose/dist/decorators/schema.decorator';
3
- import { Schema } from 'mongoose';
4
- import type { MaybeEntity } from '../../../../abstracts/abstract.entity';
5
- import { $collection } from '../../../../abstracts/abstract.entity';
6
- import { ProductEntity } from '../../../inventory/products/product.entity';
7
- import { ProductSchema } from '../../../inventory/products/product.schema';
8
-
9
- @Collection($collection)
10
- export class ItemEntity {
11
- @Prop({ ref: ProductSchema.name, type: Schema.Types.ObjectId })
12
- public product: MaybeEntity<ProductEntity>;
13
-
14
- @Prop({ default: 0, type: Schema.Types.Number })
15
- public price?: number;
16
-
17
- @Prop({ type: Schema.Types.Number })
18
- public quantity: number;
19
-
20
- @Prop({ type: Schema.Types.String })
21
- public description: string;
22
- }
23
-
24
- export const ItemSchema = SchemaFactory.createForClass(ItemEntity);
@@ -1,6 +0,0 @@
1
- export enum OrderStatus {
2
- CREATED = 'CREATED',
3
- ACCEPTED = 'ACCEPTED',
4
- COMPLETED = 'COMPLETED',
5
- CANCELED = 'CANCELED',
6
- }