@merkaly/api 0.2.4-5 → 0.2.4-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 (260) hide show
  1. package/.DS_Store +0 -0
  2. package/.bin/deploy.sh +9 -0
  3. package/.bin/package.sh +7 -0
  4. package/.docker/Dockerfile +21 -0
  5. package/.dockerignore +12 -0
  6. package/.env +21 -0
  7. package/.eslintignore +8 -0
  8. package/.eslintrc.js +35 -0
  9. package/.github/dependabot.yml +17 -0
  10. package/.github/semantic.yml +5 -0
  11. package/.github/workflows/pull_request.yml +35 -0
  12. package/.gitignore +42 -0
  13. package/.husky/.gitignore +1 -0
  14. package/.husky/commit-msg +5 -0
  15. package/.husky/common.sh +8 -0
  16. package/.husky/pre-commit +5 -0
  17. package/.husky/pre-push +4 -0
  18. package/.idea/.gitignore +5 -0
  19. package/.idea/api.iml +13 -0
  20. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  21. package/.idea/inspectionProfiles/Project_Default.xml +11 -0
  22. package/.idea/modules.xml +8 -0
  23. package/.idea/vcs.xml +12 -0
  24. package/.idea/workspace.xml +2320 -0
  25. package/.output/modules/sales/orders/billing/billing.entity.d.ts +8 -6
  26. package/.output/modules/sales/orders/billing/billing.entity.js +14 -9
  27. package/.output/modules/sales/orders/billing/billing.types.d.ts +9 -0
  28. package/.output/modules/sales/orders/billing/billing.types.js +14 -0
  29. package/.output/modules/sales/orders/billing/billing.validator.d.ts +6 -10
  30. package/.output/modules/sales/orders/billing/billing.validator.js +10 -15
  31. package/.output/modules/sales/orders/{address → billing/entities}/address.entity.d.ts +2 -1
  32. package/.output/modules/sales/orders/{address → billing/entities}/address.entity.js +17 -17
  33. package/.output/modules/sales/orders/billing/entities/customer.entity.d.ts +5 -0
  34. package/.output/modules/sales/orders/billing/entities/customer.entity.js +52 -0
  35. package/.output/modules/sales/orders/billing/entities/status.entity.d.ts +6 -0
  36. package/.output/modules/sales/orders/billing/entities/status.entity.js +37 -0
  37. package/.output/modules/sales/orders/{address → billing/validators}/address.validator.d.ts +2 -1
  38. package/.output/modules/sales/orders/{address → billing/validators}/address.validator.js +12 -14
  39. package/.output/modules/sales/orders/billing/validators/customer.validator.d.ts +5 -0
  40. package/.output/modules/sales/orders/billing/validators/customer.validator.js +36 -0
  41. package/.output/modules/sales/orders/customer/customer.validator.d.ts +1 -1
  42. package/.output/modules/sales/orders/customer/customer.validator.js +8 -8
  43. package/.output/modules/sales/orders/order.entity.d.ts +1 -1
  44. package/.output/modules/sales/orders/order.validator.d.ts +2 -2
  45. package/.output/modules/sales/orders/order.validator.js +3 -4
  46. package/.output/modules/sales/orders/shipping/entities/address.entity.d.ts +10 -0
  47. package/.output/modules/sales/orders/shipping/entities/address.entity.js +68 -0
  48. package/.output/modules/sales/orders/shipping/entities/customer.entity.d.ts +5 -0
  49. package/.output/modules/sales/orders/shipping/entities/customer.entity.js +52 -0
  50. package/.output/modules/sales/orders/shipping/entities/status.entity.d.ts +6 -0
  51. package/.output/modules/sales/orders/shipping/entities/status.entity.js +37 -0
  52. package/.output/modules/sales/orders/shipping/shipping.entity.d.ts +8 -6
  53. package/.output/modules/sales/orders/shipping/shipping.entity.js +14 -9
  54. package/.output/modules/sales/orders/shipping/shipping.types.d.ts +11 -0
  55. package/.output/modules/sales/orders/shipping/shipping.types.js +16 -0
  56. package/.output/modules/sales/orders/shipping/shipping.validator.d.ts +6 -9
  57. package/.output/modules/sales/orders/shipping/shipping.validator.js +10 -14
  58. package/.output/modules/sales/orders/shipping/validators/address.validator.d.ts +10 -0
  59. package/.output/modules/sales/orders/shipping/validators/address.validator.js +56 -0
  60. package/.output/modules/sales/orders/shipping/validators/customer.validator.d.ts +5 -0
  61. package/.output/modules/sales/orders/shipping/validators/customer.validator.js +36 -0
  62. package/authCertificate.pem +19 -0
  63. package/cloudbuild.yaml +20 -0
  64. package/commitlint.config.js +3 -0
  65. package/jest.config.js +14 -0
  66. package/merkaly-api-0.2.4-6.tgz +0 -0
  67. package/nest-cli.json +9 -0
  68. package/package.json +8 -7
  69. package/serviceAccount.json +7 -0
  70. package/src/abstract/absctract.listener.ts +2 -0
  71. package/src/abstract/abstract.controller.ts +27 -0
  72. package/src/abstract/abstract.entity.ts +19 -0
  73. package/src/abstract/abstract.exception.ts +56 -0
  74. package/src/abstract/abstract.fixture.ts +7 -0
  75. package/src/abstract/abstract.migration.ts +13 -0
  76. package/src/abstract/abstract.repository.ts +79 -0
  77. package/src/abstract/abstract.router.ts +7 -0
  78. package/src/abstract/abstract.validator.ts +62 -0
  79. package/src/app.config.ts +57 -0
  80. package/src/app.console.ts +30 -0
  81. package/src/app.controller.ts +48 -0
  82. package/src/app.migration.ts +7 -0
  83. package/src/app.module.ts +92 -0
  84. package/src/app.strategy.ts +25 -0
  85. package/src/commands/assets.command.ts +38 -0
  86. package/src/commands/deploy.command.ts +6 -0
  87. package/src/commands/fixture.command.ts +11 -0
  88. package/src/commands/generate.command.ts +286 -0
  89. package/src/decorators/public.decorator.ts +5 -0
  90. package/src/decorators/user.decorator.ts +21 -0
  91. package/src/exceptions/missing-identity.exception.ts +11 -0
  92. package/src/exceptions/store-not-implemented.exception.ts +13 -0
  93. package/src/exceptions/store-not-recognized.exception.ts +11 -0
  94. package/src/guards/auth.guard.ts +43 -0
  95. package/src/guards/organization.guard.ts +39 -0
  96. package/src/interceptors/mongo.interceptor.ts +16 -0
  97. package/src/main.ts +37 -0
  98. package/src/middlewares/logger.middleware.ts +15 -0
  99. package/src/middlewares/organization.middleware.ts +76 -0
  100. package/src/migrations/1667226478717-product_price_enhance.ts +29 -0
  101. package/src/migrations/1667329249561-product_add_seo_code_dimension.ts +37 -0
  102. package/src/migrations/1667601099139-product_activve_and_hashtag.ts +35 -0
  103. package/src/migrations/1668136428972-content_banners-use-as-image.ts +56 -0
  104. package/src/migrations/1680483744321-order-billing-shipping-status.ts +32 -0
  105. package/src/modules/assets/asset.controller.ts +33 -0
  106. package/src/modules/assets/asset.entity.ts +26 -0
  107. package/src/modules/assets/asset.module.ts +21 -0
  108. package/src/modules/assets/asset.repository.ts +51 -0
  109. package/src/modules/assets/asset.schema.ts +4 -0
  110. package/src/modules/assets/asset.service.ts +41 -0
  111. package/src/modules/auth/auth.controller.ts +42 -0
  112. package/src/modules/auth/auth.module.ts +18 -0
  113. package/src/modules/auth/logout.ts +0 -0
  114. package/src/modules/command.module.ts +19 -0
  115. package/src/modules/content/banners/banner.controller.ts +56 -0
  116. package/src/modules/content/banners/banner.entity.ts +17 -0
  117. package/src/modules/content/banners/banner.fixture.ts +19 -0
  118. package/src/modules/content/banners/banner.listener.ts +6 -0
  119. package/src/modules/content/banners/banner.module.ts +21 -0
  120. package/src/modules/content/banners/banner.repository.ts +38 -0
  121. package/src/modules/content/banners/banner.schema.ts +4 -0
  122. package/src/modules/content/banners/banner.types.ts +7 -0
  123. package/src/modules/content/banners/banner.validator.ts +19 -0
  124. package/src/modules/content/content.module.ts +20 -0
  125. package/src/modules/content/pages/page.controller.ts +53 -0
  126. package/src/modules/content/pages/page.entity.ts +27 -0
  127. package/src/modules/content/pages/page.fixture.ts +19 -0
  128. package/src/modules/content/pages/page.listener.ts +6 -0
  129. package/src/modules/content/pages/page.module.ts +21 -0
  130. package/src/modules/content/pages/page.repository.ts +44 -0
  131. package/src/modules/content/pages/page.schema.ts +4 -0
  132. package/src/modules/content/pages/page.types.ts +9 -0
  133. package/src/modules/content/pages/page.validator.ts +29 -0
  134. package/src/modules/global.module.ts +70 -0
  135. package/src/modules/insight/controllers/address.controller.ts +29 -0
  136. package/src/modules/insight/controllers/order.controller.ts +70 -0
  137. package/src/modules/insight/controllers/products.controller.ts +18 -0
  138. package/src/modules/insight/insight.module.ts +24 -0
  139. package/src/modules/insight/validators/order.validator.ts +10 -0
  140. package/src/modules/inventory/brands/brand.controller.ts +59 -0
  141. package/src/modules/inventory/brands/brand.entity.ts +14 -0
  142. package/src/modules/inventory/brands/brand.exception.ts +9 -0
  143. package/src/modules/inventory/brands/brand.listener.ts +18 -0
  144. package/src/modules/inventory/brands/brand.module.ts +19 -0
  145. package/src/modules/inventory/brands/brand.repository.ts +39 -0
  146. package/src/modules/inventory/brands/brand.schema.ts +4 -0
  147. package/src/modules/inventory/brands/brand.validator.ts +23 -0
  148. package/src/modules/inventory/categories/category.controller.ts +59 -0
  149. package/src/modules/inventory/categories/category.entity.ts +21 -0
  150. package/src/modules/inventory/categories/category.exception.ts +9 -0
  151. package/src/modules/inventory/categories/category.fixture.ts +18 -0
  152. package/src/modules/inventory/categories/category.listener.ts +17 -0
  153. package/src/modules/inventory/categories/category.module.ts +19 -0
  154. package/src/modules/inventory/categories/category.repository.ts +40 -0
  155. package/src/modules/inventory/categories/category.schema.ts +4 -0
  156. package/src/modules/inventory/categories/category.validator.ts +30 -0
  157. package/src/modules/inventory/inventory.module.ts +22 -0
  158. package/src/modules/inventory/products/entities/code.entity.ts +15 -0
  159. package/src/modules/inventory/products/entities/dimension.entity.ts +18 -0
  160. package/src/modules/inventory/products/entities/price.entity.ts +12 -0
  161. package/src/modules/inventory/products/entities/seo.entity.ts +15 -0
  162. package/src/modules/inventory/products/product.controller.ts +59 -0
  163. package/src/modules/inventory/products/product.entity.ts +53 -0
  164. package/src/modules/inventory/products/product.exception.ts +9 -0
  165. package/src/modules/inventory/products/product.fixture.ts +19 -0
  166. package/src/modules/inventory/products/product.listener.ts +27 -0
  167. package/src/modules/inventory/products/product.module.ts +20 -0
  168. package/src/modules/inventory/products/product.repository.ts +108 -0
  169. package/src/modules/inventory/products/product.schema.ts +15 -0
  170. package/src/modules/inventory/products/product.validator.ts +71 -0
  171. package/src/modules/inventory/products/validators/code.validator.ts +15 -0
  172. package/src/modules/inventory/products/validators/dimension.validator.ts +19 -0
  173. package/src/modules/inventory/products/validators/price.validator.ts +10 -0
  174. package/src/modules/inventory/products/validators/seo.validator.ts +15 -0
  175. package/src/modules/inventory/properties/property.controller.ts +56 -0
  176. package/src/modules/inventory/properties/property.entity.ts +18 -0
  177. package/src/modules/inventory/properties/property.exception.ts +9 -0
  178. package/src/modules/inventory/properties/property.listener.ts +20 -0
  179. package/src/modules/inventory/properties/property.module.ts +21 -0
  180. package/src/modules/inventory/properties/property.repository.ts +23 -0
  181. package/src/modules/inventory/properties/property.schema.ts +4 -0
  182. package/src/modules/inventory/properties/property.validator.ts +27 -0
  183. package/src/modules/sales/clients/client.controller.ts +60 -0
  184. package/src/modules/sales/clients/client.entity.ts +25 -0
  185. package/src/modules/sales/clients/client.exception.ts +9 -0
  186. package/src/modules/sales/clients/client.listener.ts +20 -0
  187. package/src/modules/sales/clients/client.module.ts +19 -0
  188. package/src/modules/sales/clients/client.repository.ts +37 -0
  189. package/src/modules/sales/clients/client.schema.ts +4 -0
  190. package/src/modules/sales/clients/client.validator.ts +43 -0
  191. package/src/modules/sales/orders/billing/billing.entity.ts +22 -0
  192. package/src/modules/sales/orders/billing/billing.types.ts +10 -0
  193. package/src/modules/sales/orders/billing/billing.validator.ts +21 -0
  194. package/src/modules/sales/orders/billing/entities/address.entity.ts +27 -0
  195. package/src/modules/sales/orders/billing/entities/customer.entity.ts +14 -0
  196. package/src/modules/sales/orders/billing/entities/status.entity.ts +16 -0
  197. package/src/modules/sales/orders/billing/validators/address.validator.ts +28 -0
  198. package/src/modules/sales/orders/billing/validators/customer.validator.ts +14 -0
  199. package/src/modules/sales/orders/customer/customer.entity.ts +14 -0
  200. package/src/modules/sales/orders/customer/customer.validator.ts +14 -0
  201. package/src/modules/sales/orders/item/item.entity.ts +21 -0
  202. package/src/modules/sales/orders/item/item.schema.ts +8 -0
  203. package/src/modules/sales/orders/item/item.validator.ts +10 -0
  204. package/src/modules/sales/orders/order.controller.ts +93 -0
  205. package/src/modules/sales/orders/order.entity.ts +47 -0
  206. package/src/modules/sales/orders/order.listener.ts +20 -0
  207. package/src/modules/sales/orders/order.module.ts +19 -0
  208. package/src/modules/sales/orders/order.repository.ts +189 -0
  209. package/src/modules/sales/orders/order.schema.ts +35 -0
  210. package/src/modules/sales/orders/order.validator.ts +72 -0
  211. package/src/modules/sales/orders/shipping/entities/address.entity.ts +27 -0
  212. package/src/modules/sales/orders/shipping/entities/customer.entity.ts +14 -0
  213. package/src/modules/sales/orders/shipping/entities/status.entity.ts +16 -0
  214. package/src/modules/sales/orders/shipping/shipping.entity.ts +25 -0
  215. package/src/modules/sales/orders/shipping/shipping.types.ts +12 -0
  216. package/src/modules/sales/orders/shipping/shipping.validator.ts +25 -0
  217. package/src/modules/sales/orders/shipping/validators/address.validator.ts +28 -0
  218. package/src/modules/sales/orders/shipping/validators/customer.validator.ts +14 -0
  219. package/src/modules/sales/orders/status/status.entity.ts +16 -0
  220. package/src/modules/sales/orders/status/status.validator.ts +8 -0
  221. package/src/modules/sales/sales.module.ts +20 -0
  222. package/src/modules/setting/connections/connection.controller.ts +27 -0
  223. package/src/modules/setting/connections/connection.module.ts +17 -0
  224. package/src/modules/setting/connections/connection.validator.ts +15 -0
  225. package/src/modules/setting/layout/layout.controller.ts +34 -0
  226. package/src/modules/setting/layout/layout.entity.ts +13 -0
  227. package/src/modules/setting/layout/layout.listener.ts +7 -0
  228. package/src/modules/setting/layout/layout.module.ts +21 -0
  229. package/src/modules/setting/layout/layout.repository.ts +29 -0
  230. package/src/modules/setting/layout/layout.schema.ts +4 -0
  231. package/src/modules/setting/members/member.controller.ts +22 -0
  232. package/src/modules/setting/members/member.module.ts +17 -0
  233. package/src/modules/setting/members/member.validator.ts +3 -0
  234. package/src/modules/setting/organization/organization.controller.ts +33 -0
  235. package/src/modules/setting/organization/organization.entity.ts +27 -0
  236. package/src/modules/setting/organization/organization.listener.ts +46 -0
  237. package/src/modules/setting/organization/organization.module.ts +21 -0
  238. package/src/modules/setting/organization/organization.repository.ts +55 -0
  239. package/src/modules/setting/organization/organization.types.ts +65 -0
  240. package/src/modules/setting/organization/organization.validator.ts +56 -0
  241. package/src/modules/setting/setting.module.ts +23 -0
  242. package/src/modules/setting/theme/theme.controller.ts +34 -0
  243. package/src/modules/setting/theme/theme.entity.ts +13 -0
  244. package/src/modules/setting/theme/theme.listener.ts +6 -0
  245. package/src/modules/setting/theme/theme.module.ts +21 -0
  246. package/src/modules/setting/theme/theme.repository.ts +23 -0
  247. package/src/modules/setting/theme/theme.schema.ts +4 -0
  248. package/src/modules/users/user.controller.ts +75 -0
  249. package/src/modules/users/user.module.ts +20 -0
  250. package/src/modules/users/user.validator.ts +28 -0
  251. package/src/providers/auth0.provider.ts +36 -0
  252. package/src/providers/storage.provider.ts +22 -0
  253. package/src/services/auth0.service.ts +7 -0
  254. package/src/services/logger.service.ts +33 -0
  255. package/src/services/mongo.service.ts +44 -0
  256. package/src/services/storage.service.ts +39 -0
  257. package/src/types.ts +19 -0
  258. package/tsconfig.json +40 -0
  259. package/tsconfig.package.json +20 -0
  260. package/yarn.lock +8782 -0
@@ -0,0 +1,19 @@
1
+ import { IsNumber, IsOptional } from 'class-validator';
2
+
3
+ export class ProductDimensionValidator {
4
+ @IsNumber()
5
+ @IsOptional()
6
+ public weight? = 0;
7
+
8
+ @IsNumber()
9
+ @IsOptional()
10
+ public height? = 0;
11
+
12
+ @IsNumber()
13
+ @IsOptional()
14
+ public width? = 0;
15
+
16
+ @IsNumber()
17
+ @IsOptional()
18
+ public depth? = 0;
19
+ }
@@ -0,0 +1,10 @@
1
+ import { IsNumber, IsOptional } from 'class-validator';
2
+
3
+ export class ProductPriceValidator {
4
+ @IsNumber()
5
+ public sale = 0;
6
+
7
+ @IsNumber()
8
+ @IsOptional()
9
+ public purchase? = 0;
10
+ }
@@ -0,0 +1,15 @@
1
+ import { IsOptional, IsString } from 'class-validator';
2
+
3
+ export class ProductSeoValidator {
4
+ @IsString()
5
+ @IsOptional()
6
+ public title? = String();
7
+
8
+ @IsString()
9
+ @IsOptional()
10
+ public slug? = String();
11
+
12
+ @IsString()
13
+ @IsOptional()
14
+ public description? = String();
15
+ }
@@ -0,0 +1,56 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ Delete,
5
+ Get,
6
+ HttpCode,
7
+ HttpStatus,
8
+ Inject,
9
+ Param,
10
+ Patch,
11
+ Post,
12
+ Query,
13
+ UseFilters,
14
+ } from '@nestjs/common';
15
+ import { ApiTags } from '@nestjs/swagger';
16
+ import { AbstractController } from '../../../abstract/abstract.controller';
17
+ import { FindValidator } from '../../../abstract/abstract.validator';
18
+ import { PropertyEntity } from './property.entity';
19
+ import { PropertyException } from './property.exception';
20
+ import { PropertyRepository } from './property.repository';
21
+ import { CreatePropertyValidator, UpdatePropertyValidator } from './property.validator';
22
+
23
+ @Controller()
24
+ @UseFilters(PropertyException)
25
+ @ApiTags('inventory')
26
+ export class PropertyController extends AbstractController<PropertyEntity> {
27
+ @Inject()
28
+ protected readonly $repository: PropertyRepository;
29
+
30
+ @Get('/')
31
+ public async find(@Query() validator: FindValidator<PropertyEntity>) {
32
+ return super.find(validator);
33
+ }
34
+
35
+ @Post('/')
36
+ @HttpCode(HttpStatus.CREATED)
37
+ public async create(@Body() validator: CreatePropertyValidator) {
38
+ return super.create(validator);
39
+ }
40
+
41
+ @Get('/:id')
42
+ public async read(@Param('id') id: string) {
43
+ return super.read(id);
44
+ }
45
+
46
+ @Patch('/:id')
47
+ public async update(@Param('id') id: string, @Body() validator: UpdatePropertyValidator) {
48
+ return super.update(id, validator);
49
+ }
50
+
51
+ @Delete('/:id')
52
+ @HttpCode(HttpStatus.NO_CONTENT)
53
+ public async delete(@Param('id') id: string) {
54
+ return super.delete(id);
55
+ }
56
+ }
@@ -0,0 +1,18 @@
1
+ import { Prop, Schema } from '@nestjs/mongoose';
2
+ import { Schema as MongoSchema } from 'mongoose';
3
+ import { AbstractEntity } from '../../../abstract/abstract.entity';
4
+ import { PropertyType } from './property.validator';
5
+
6
+ @Schema({ timestamps: true })
7
+ export class PropertyEntity extends AbstractEntity {
8
+ public static readonly $index = 'inventory_properties';
9
+
10
+ @Prop({ type: MongoSchema.Types.String, required: true, unique: true, length: 32 })
11
+ public name: string;
12
+
13
+ @Prop({ type: MongoSchema.Types.String, required: true, length: 64 })
14
+ public title: string;
15
+
16
+ @Prop({ type: MongoSchema.Types.String, default: PropertyType.STRING })
17
+ public type: string;
18
+ }
@@ -0,0 +1,9 @@
1
+ import { Catch, HttpException } from '@nestjs/common';
2
+ import { AbstractException } from '../../../abstract/abstract.exception';
3
+
4
+ @Catch()
5
+ export class PropertyException extends AbstractException {
6
+ public handleError(exception: HttpException) {
7
+ return exception;
8
+ }
9
+ }
@@ -0,0 +1,20 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { AbsctractListener } from '../../../abstract/absctract.listener';
3
+
4
+ export enum PropertyEvent {
5
+ ALL_EVENTS = 'database.inventory.property.**',
6
+
7
+ PRE_CREATE = 'database.inventory.property.create.pre',
8
+ POST_CREATE = 'database.inventory.property.create.post',
9
+
10
+ PRE_UPDATE = 'database.inventory.property.update.pre',
11
+ POST_UPDATE = 'database.inventory.property.update.post',
12
+
13
+ PRE_DELETE = 'database.inventory.property.delete.pre',
14
+ POST_DELETE = 'database.inventory.property.delete.post',
15
+ }
16
+
17
+ @Injectable()
18
+ export class PropertyListener extends AbsctractListener {
19
+
20
+ }
@@ -0,0 +1,21 @@
1
+ import { Module, ModuleMetadata } from '@nestjs/common';
2
+ import { AbstractRouter } from '../../../abstract/abstract.router';
3
+ import { PropertyController } from './property.controller';
4
+ import { PropertyListener } from './property.listener';
5
+ import { PropertyRepository } from './property.repository';
6
+
7
+ export const metadata: ModuleMetadata = {
8
+ imports: [],
9
+ controllers: [PropertyController],
10
+ providers: [PropertyRepository, PropertyListener],
11
+ exports: [PropertyRepository],
12
+ };
13
+
14
+ @Module(metadata)
15
+ export class PropertyModule extends AbstractRouter {
16
+ public static readonly path = '/properties';
17
+
18
+ public static readonly module = PropertyModule;
19
+
20
+ public static readonly children = metadata.imports;
21
+ }
@@ -0,0 +1,23 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { InjectModel } from '@nestjs/mongoose';
3
+ import { Model } from 'mongoose';
4
+ import { AbstractRepository } from '../../../abstract/abstract.repository';
5
+ import { PropertyEntity } from './property.entity';
6
+
7
+ @Injectable()
8
+ export class PropertyRepository extends AbstractRepository<PropertyEntity> {
9
+ @InjectModel(PropertyEntity.$index)
10
+ public readonly $model: Model<PropertyEntity>;
11
+
12
+ public create(params: any): Promise<PropertyEntity> {
13
+ return Promise.resolve(undefined);
14
+ }
15
+
16
+ public delete(id: string): Promise<void> {
17
+ return Promise.resolve(undefined);
18
+ }
19
+
20
+ public update(id: string, params: unknown): Promise<PropertyEntity> {
21
+ return Promise.resolve(undefined);
22
+ }
23
+ }
@@ -0,0 +1,4 @@
1
+ import { SchemaFactory } from '@nestjs/mongoose';
2
+ import { PropertyEntity } from './property.entity';
3
+
4
+ export const PropertySchema = SchemaFactory.createForClass(PropertyEntity);
@@ -0,0 +1,27 @@
1
+ import { IsOptional, IsString } from 'class-validator';
2
+ import { AbstractValidator } from "../../../abstract/abstract.validator";
3
+
4
+ export enum PropertyType {
5
+ STRING = 'STRING',
6
+ }
7
+
8
+ export class CreatePropertyValidator extends AbstractValidator {
9
+ @IsString()
10
+ public name: string;
11
+
12
+ @IsString()
13
+ public title: string;
14
+
15
+ @IsString()
16
+ public type: string;
17
+ }
18
+
19
+ export class UpdatePropertyValidator extends AbstractValidator {
20
+ @IsString()
21
+ @IsOptional()
22
+ public name?: string;
23
+
24
+ @IsString()
25
+ @IsOptional()
26
+ public title?: string;
27
+ }
@@ -0,0 +1,60 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ Delete,
5
+ Get,
6
+ HttpCode,
7
+ HttpStatus,
8
+ Inject,
9
+ Param,
10
+ Patch,
11
+ Post,
12
+ Query,
13
+ UseFilters,
14
+ } from '@nestjs/common';
15
+ import { ApiTags } from '@nestjs/swagger';
16
+ import { AbstractController } from '../../../abstract/abstract.controller';
17
+ import { FindValidator } from '../../../abstract/abstract.validator';
18
+ import { Auth0Service } from '../../../services/auth0.service';
19
+ import { ClientEntity } from './client.entity';
20
+ import { ClientException } from './client.exception';
21
+ import { ClientRepository } from './client.repository';
22
+ import { CreateClientValidator, UpdateClientValidator } from './client.validator';
23
+
24
+ @Controller()
25
+ @UseFilters(ClientException)
26
+ @ApiTags('orders')
27
+ export class ClientController extends AbstractController<ClientEntity> {
28
+ @Inject()
29
+ protected readonly $repository: ClientRepository;
30
+
31
+ @Inject()
32
+ protected readonly $auth0: Auth0Service;
33
+
34
+ @Get('/')
35
+ public async find(@Query() validator: FindValidator<ClientEntity>) {
36
+ return this.$repository.find(validator);
37
+ }
38
+
39
+ @Get('/:id')
40
+ public async read(@Param('id') id: string) {
41
+ return this.$repository.read(id);
42
+ }
43
+
44
+ @Post('/')
45
+ @HttpCode(HttpStatus.CREATED)
46
+ public async create(@Body() validator: CreateClientValidator) {
47
+ return this.$repository.create(validator);
48
+ }
49
+
50
+ @Patch('/:id')
51
+ public async update(@Param('id') id: string, @Body() validator: UpdateClientValidator) {
52
+ return this.$repository.update(id, validator);
53
+ }
54
+
55
+ @Delete('/:id')
56
+ @HttpCode(HttpStatus.NO_CONTENT)
57
+ public async delete(@Param('id') id: string) {
58
+ return this.$repository.delete(id);
59
+ }
60
+ }
@@ -0,0 +1,25 @@
1
+ import { Prop, Schema as Collection } from '@nestjs/mongoose';
2
+ import { User } from 'auth0';
3
+ import { Schema } from 'mongoose';
4
+ import { AbstractEntity } from '../../../abstract/abstract.entity';
5
+ import { MetaAddress } from "../../../types";
6
+
7
+ @Collection({ timestamps: true })
8
+ export class ClientEntity extends AbstractEntity implements User {
9
+ public static readonly $index = 'store_clients';
10
+
11
+ @Prop({ type: Schema.Types.String, required: true })
12
+ public readonly name: string;
13
+
14
+ @Prop({ type: Schema.Types.String, unique: true, required: true })
15
+ public readonly email: string;
16
+
17
+ @Prop({ type: Schema.Types.String, default: null })
18
+ public readonly phone?: string;
19
+
20
+ @Prop({ type: Schema.Types.String, unique: true })
21
+ public readonly identificationNumber: string;
22
+
23
+ @Prop({ type: Schema.Types.Array, default: [] })
24
+ public readonly addresses: MetaAddress[] = [];
25
+ }
@@ -0,0 +1,9 @@
1
+ import { Catch, HttpException } from '@nestjs/common';
2
+ import { AbstractException } from '../../../abstract/abstract.exception';
3
+
4
+ @Catch()
5
+ export class ClientException extends AbstractException {
6
+ public handleError(exception: HttpException) {
7
+ return exception;
8
+ }
9
+ }
@@ -0,0 +1,20 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { AbsctractListener } from '../../../abstract/absctract.listener';
3
+
4
+ export enum ClientEvent {
5
+ ALL_EVENTS = 'database.store.client.**',
6
+
7
+ PRE_CREATE = 'database.store.client.create.pre',
8
+ POST_CREATE = 'database.store.client.create.post',
9
+
10
+ PRE_UPDATE = 'database.store.client.update.pre',
11
+ POST_UPDATE = 'database.store.client.update.post',
12
+
13
+ PRE_DELETE = 'database.store.client.delete.pre',
14
+ POST_DELETE = 'database.store.client.delete.post',
15
+ }
16
+
17
+ @Injectable()
18
+ export class ClientListener extends AbsctractListener {
19
+
20
+ }
@@ -0,0 +1,19 @@
1
+ import { Module, ModuleMetadata } from '@nestjs/common';
2
+ import { AbstractRouter } from '../../../abstract/abstract.router';
3
+ import { ClientController } from './client.controller';
4
+ import { ClientListener } from './client.listener';
5
+ import { ClientRepository } from './client.repository';
6
+
7
+ export const metadata: ModuleMetadata = {
8
+ imports: [],
9
+ controllers: [ClientController],
10
+ providers: [ClientRepository, ClientListener],
11
+ exports: [ClientRepository],
12
+ };
13
+
14
+ @Module(metadata)
15
+ export class ClientModule extends AbstractRouter {
16
+ public static readonly path = '/clients';
17
+
18
+ public static readonly module = ClientModule;
19
+ }
@@ -0,0 +1,37 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { InjectModel } from '@nestjs/mongoose';
3
+ import { Model, UpdateQuery } from 'mongoose';
4
+ import { Mutable } from 'type-fest';
5
+ import { AbstractRepository } from '../../../abstract/abstract.repository';
6
+ import { ClientEntity } from './client.entity';
7
+ import { CreateClientValidator, UpdateClientValidator } from './client.validator';
8
+
9
+ @Injectable()
10
+ export class ClientRepository extends AbstractRepository<ClientEntity> {
11
+ @InjectModel(ClientEntity.$index)
12
+ public readonly $model: Model<ClientEntity>;
13
+
14
+ public async create(validator: CreateClientValidator) {
15
+ const client: Mutable<ClientEntity> = new this.$model();
16
+
17
+ client.name = validator.name;
18
+ client.email = validator.email;
19
+ client.phone = validator.phone;
20
+ client.identificationNumber = validator.identificationNumber;
21
+ client.addresses = validator.addresses;
22
+
23
+ return super.$create(client);
24
+ }
25
+
26
+ public async update(id: string, validator: UpdateClientValidator): Promise<ClientEntity> {
27
+ const query: UpdateQuery<ClientEntity> = {
28
+ $set: {},
29
+ };
30
+
31
+ return super.$update(id, query);
32
+ }
33
+
34
+ public delete(id: string): Promise<void> {
35
+ return super.$delete(id);
36
+ }
37
+ }
@@ -0,0 +1,4 @@
1
+ import { SchemaFactory } from '@nestjs/mongoose';
2
+ import { ClientEntity } from './client.entity';
3
+
4
+ export const ClientSchema = SchemaFactory.createForClass(ClientEntity);
@@ -0,0 +1,43 @@
1
+ import { Transform } from 'class-transformer';
2
+ import { IsArray, IsEmail, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
3
+ import { MetaAddress } from "../../../types";
4
+ import { AbstractValidator } from "../../../abstract/abstract.validator";
5
+
6
+ export class CreateClientValidator 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
+ @IsString()
19
+ public identificationNumber: string;
20
+
21
+ @IsArray()
22
+ public addresses: MetaAddress[];
23
+ }
24
+
25
+ export class UpdateClientValidator extends CreateClientValidator {
26
+ @IsString()
27
+ @IsOptional()
28
+ public name: string;
29
+
30
+ @IsEmail()
31
+ @Transform(({ value }) => String(value).toLowerCase())
32
+ @IsOptional()
33
+ public email: string;
34
+
35
+ @IsPhoneNumber()
36
+ @IsOptional()
37
+ public phone: string;
38
+
39
+ @IsString()
40
+ @IsOptional()
41
+ public identificationNumber: string;
42
+ }
43
+
@@ -0,0 +1,22 @@
1
+ import { Prop } from '@nestjs/mongoose';
2
+ import { Schema as Collection } from '@nestjs/mongoose/dist/decorators/schema.decorator';
3
+ import { Schema } from 'mongoose';
4
+ import { BillingMethod } from "./billing.types";
5
+ import { BillingStatusEntity } from "./entities/status.entity";
6
+ import { BillingAddressEntity } from "./entities/address.entity";
7
+ import { BillingCustomerEntity } from "./entities/customer.entity";
8
+
9
+ @Collection({})
10
+ export class BillingEntity extends Map {
11
+ @Prop({ type: Schema.Types.Map, ref: () => BillingAddressEntity, default: new BillingAddressEntity() })
12
+ public address = new BillingAddressEntity();
13
+
14
+ @Prop({ type: Schema.Types.Map, ref: () => BillingCustomerEntity, default: new BillingCustomerEntity() })
15
+ public customer = new BillingCustomerEntity();
16
+
17
+ @Prop({ type: Schema.Types.String, enum: BillingMethod, required: true })
18
+ public method: BillingMethod;
19
+
20
+ @Prop({ type: Schema.Types.Array, default: [] })
21
+ public status: BillingStatusEntity[] = [];
22
+ }
@@ -0,0 +1,10 @@
1
+ export enum BillingMethod {
2
+ CASH = 'CASH',
3
+ CARD = 'CARD',
4
+ TRANSFER = 'TRANSFER',
5
+ }
6
+
7
+ export enum BillingStatus {
8
+ UNPAID = 'UNPAID',
9
+ PAID = 'PAID',
10
+ }
@@ -0,0 +1,21 @@
1
+ import { Type } from 'class-transformer';
2
+ import { IsEnum, IsNotEmptyObject, ValidateNested } from 'class-validator';
3
+ import 'reflect-metadata';
4
+ import { BillingMethod } from "./billing.types";
5
+ import { BillingCustomerValidator } from "./validators/customer.validator";
6
+ import { BillingAddressValidator } from "./validators/address.validator";
7
+
8
+ export class CreateBillingValidator {
9
+ @ValidateNested()
10
+ @Type(() => BillingCustomerValidator)
11
+ @IsNotEmptyObject()
12
+ public customer = new BillingCustomerValidator();
13
+
14
+ @ValidateNested()
15
+ @Type(() => BillingAddressValidator)
16
+ @IsNotEmptyObject()
17
+ public address = new BillingAddressValidator();
18
+
19
+ @IsEnum(BillingMethod)
20
+ public method: BillingMethod;
21
+ }
@@ -0,0 +1,27 @@
1
+ import { Prop, Schema as Collection } from '@nestjs/mongoose';
2
+ import { Schema } from 'mongoose';
3
+ import { MetaAddress } from "../../../../../types";
4
+
5
+ @Collection()
6
+ export class BillingAddressEntity extends Map implements MetaAddress {
7
+ @Prop({ type: Schema.Types.String, required: true })
8
+ public country: string;
9
+
10
+ @Prop({ type: Schema.Types.String, required: true })
11
+ public code: string;
12
+
13
+ @Prop({ type: Schema.Types.String, required: true })
14
+ public street: string;
15
+
16
+ @Prop({ type: Schema.Types.String })
17
+ public number: string;
18
+
19
+ @Prop({ type: Schema.Types.String })
20
+ public complement: string;
21
+
22
+ @Prop({ type: Schema.Types.String, required: true })
23
+ public city: string;
24
+
25
+ @Prop({ type: Schema.Types.String, required: true })
26
+ public state: string;
27
+ }
@@ -0,0 +1,14 @@
1
+ import { Prop, Schema as Collection } from '@nestjs/mongoose';
2
+ import { Schema } from 'mongoose';
3
+
4
+ @Collection({})
5
+ export class BillingCustomerEntity extends Map {
6
+ @Prop({ type: Schema.Types.String, required: true })
7
+ public name: string;
8
+
9
+ @Prop({ type: Schema.Types.String })
10
+ public email: string;
11
+
12
+ @Prop({ type: Schema.Types.String })
13
+ public phone: string;
14
+ }
@@ -0,0 +1,16 @@
1
+ import { Prop } from '@nestjs/mongoose';
2
+ import { Schema as Collection } from '@nestjs/mongoose/dist/decorators/schema.decorator';
3
+ import { Schema } from 'mongoose';
4
+ import { BillingStatus } from "../billing.types";
5
+
6
+ @Collection({ timestamps: true })
7
+ export class BillingStatusEntity {
8
+ @Prop({ type: Schema.Types.String, enum: BillingStatus, required: true })
9
+ public name: BillingStatus;
10
+
11
+ @Prop({ type: Schema.Types.String })
12
+ public user: string;
13
+
14
+ @Prop({ type: Schema.Types.Date })
15
+ public date;
16
+ }
@@ -0,0 +1,28 @@
1
+ import { IsISO31661Alpha2, IsOptional, IsString } from 'class-validator';
2
+ import { MetaAddress } from "../../../../../types";
3
+
4
+ export class BillingAddressValidator implements MetaAddress {
5
+ @IsISO31661Alpha2()
6
+ public country = String();
7
+
8
+ @IsString()
9
+ public code = String();
10
+
11
+ @IsString()
12
+ public street = String();
13
+
14
+ @IsString()
15
+ @IsOptional()
16
+ public number = String();
17
+
18
+ @IsString()
19
+ @IsOptional()
20
+ public complement?: string = undefined;
21
+
22
+ @IsString()
23
+ public city = String();
24
+
25
+ @IsString()
26
+ public state = String();
27
+ }
28
+
@@ -0,0 +1,14 @@
1
+ import { IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator';
2
+
3
+ export class BillingCustomerValidator {
4
+ @IsString()
5
+ @IsNotEmpty()
6
+ public name = String();
7
+
8
+ @IsEmail()
9
+ public email = String();
10
+
11
+ @IsString()
12
+ @IsOptional()
13
+ public phone?: string = undefined;
14
+ }
@@ -0,0 +1,14 @@
1
+ import { Prop, Schema as Collection } from '@nestjs/mongoose';
2
+ import { Schema } from 'mongoose';
3
+
4
+ @Collection()
5
+ export class CustomerEntity extends Map {
6
+ @Prop({ type: Schema.Types.String, required: true })
7
+ public name: string;
8
+
9
+ @Prop({ type: Schema.Types.String })
10
+ public email: string;
11
+
12
+ @Prop({ type: Schema.Types.String })
13
+ public phone: string;
14
+ }
@@ -0,0 +1,14 @@
1
+ import { IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator';
2
+
3
+ export class CustomerValidator {
4
+ @IsString()
5
+ @IsNotEmpty()
6
+ public name = String();
7
+
8
+ @IsEmail()
9
+ public email = String();
10
+
11
+ @IsString()
12
+ @IsOptional()
13
+ public phone?: string = undefined;
14
+ }