@merkaly/api 0.1.7 → 0.1.9-1

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 (125) hide show
  1. package/package.json +32 -40
  2. package/src/account/account.module.d.ts +4 -0
  3. package/src/account/account.module.ts +15 -0
  4. package/src/account/auth/auth.controller.d.ts +10 -0
  5. package/src/account/auth/auth.controller.ts +38 -0
  6. package/src/account/auth/auth.module.d.ts +4 -0
  7. package/src/account/auth/auth.module.ts +26 -0
  8. package/src/account/auth/auth.repository.d.ts +6 -0
  9. package/src/account/auth/auth.repository.ts +39 -0
  10. package/src/account/organizations/members/member.controller.d.ts +9 -0
  11. package/src/account/organizations/members/member.controller.ts +33 -0
  12. package/src/account/organizations/members/member.module.d.ts +4 -0
  13. package/src/account/organizations/members/member.module.ts +14 -0
  14. package/src/account/organizations/members/member.repository.d.ts +12 -0
  15. package/src/account/organizations/members/member.repository.ts +43 -0
  16. package/src/account/organizations/members/member.validator.d.ts +2 -0
  17. package/src/account/organizations/members/member.validator.ts +3 -0
  18. package/src/account/organizations/organization.controller.d.ts +11 -0
  19. package/src/account/organizations/organization.controller.ts +42 -0
  20. package/src/account/organizations/organization.entity.d.ts +3 -1
  21. package/src/account/organizations/organization.entity.ts +4 -1
  22. package/src/account/organizations/organization.module.d.ts +4 -0
  23. package/src/account/organizations/organization.module.ts +16 -0
  24. package/src/account/organizations/organization.repository.d.ts +12 -0
  25. package/src/account/organizations/organization.repository.ts +74 -0
  26. package/src/account/organizations/organization.validator.ts +11 -0
  27. package/src/account/roles/role.controller.d.ts +11 -0
  28. package/src/account/roles/role.controller.ts +39 -0
  29. package/src/account/roles/role.module.d.ts +4 -0
  30. package/src/account/roles/role.module.ts +15 -0
  31. package/src/account/roles/role.repository.d.ts +12 -0
  32. package/src/account/roles/role.repository.ts +63 -0
  33. package/src/account/roles/users/user.controller.d.ts +8 -0
  34. package/src/account/roles/users/user.controller.ts +28 -0
  35. package/src/account/roles/users/user.module.d.ts +4 -0
  36. package/src/account/roles/users/user.module.ts +14 -0
  37. package/src/account/roles/users/user.repository.d.ts +11 -0
  38. package/src/account/roles/users/user.repository.ts +34 -0
  39. package/src/account/roles/users/user.validator.d.ts +2 -4
  40. package/src/account/roles/users/user.validator.ts +2 -9
  41. package/src/account/users/roles/role.controller.d.ts +9 -0
  42. package/src/account/users/roles/role.controller.ts +34 -0
  43. package/src/account/users/roles/role.module.d.ts +4 -0
  44. package/src/account/users/roles/role.module.ts +14 -0
  45. package/src/account/users/roles/role.repository.d.ts +12 -0
  46. package/src/account/users/roles/role.repository.ts +38 -0
  47. package/src/account/users/roles/role.validator.d.ts +2 -4
  48. package/src/account/users/roles/role.validator.ts +2 -9
  49. package/src/account/users/user.controller.d.ts +11 -0
  50. package/src/account/users/user.controller.ts +39 -0
  51. package/src/account/users/user.module.d.ts +4 -0
  52. package/src/account/users/user.module.ts +15 -0
  53. package/src/account/users/user.repository.d.ts +12 -0
  54. package/src/account/users/user.repository.ts +53 -0
  55. package/src/account/users/user.validator.d.ts +3 -3
  56. package/src/account/users/user.validator.ts +7 -7
  57. package/src/app.d.ts +1 -0
  58. package/src/app.emitter.d.ts +16 -0
  59. package/src/app.emitter.ts +27 -0
  60. package/src/app.entity.d.ts +7 -0
  61. package/src/app.module.d.ts +9 -0
  62. package/src/app.module.ts +45 -0
  63. package/src/app.repository.d.ts +5 -0
  64. package/src/app.repository.ts +12 -0
  65. package/src/app.routes.d.ts +3 -0
  66. package/src/app.routes.ts +61 -0
  67. package/src/inventory/brands/brand.controller.d.ts +11 -0
  68. package/src/inventory/brands/brand.controller.ts +41 -0
  69. package/src/inventory/brands/brand.module.d.ts +4 -0
  70. package/src/inventory/brands/brand.module.ts +14 -0
  71. package/src/inventory/brands/brand.repository.d.ts +13 -0
  72. package/src/inventory/brands/brand.repository.ts +36 -0
  73. package/src/inventory/categories/category.controller.d.ts +11 -0
  74. package/src/inventory/categories/category.controller.ts +43 -0
  75. package/src/inventory/categories/category.module.d.ts +4 -0
  76. package/src/inventory/categories/category.module.ts +14 -0
  77. package/src/inventory/categories/category.repository.d.ts +13 -0
  78. package/src/inventory/categories/category.repository.ts +36 -0
  79. package/src/inventory/inventory.module.d.ts +4 -0
  80. package/src/inventory/inventory.module.ts +17 -0
  81. package/src/inventory/products/media/media.controller.d.ts +7 -0
  82. package/src/inventory/products/media/media.controller.ts +23 -0
  83. package/src/inventory/products/media/media.module.d.ts +4 -0
  84. package/src/inventory/products/media/media.module.ts +14 -0
  85. package/src/inventory/products/media/media.repository.d.ts +10 -0
  86. package/src/inventory/products/media/media.repository.ts +22 -0
  87. package/src/inventory/products/product.controller.d.ts +12 -0
  88. package/src/inventory/products/product.controller.ts +59 -0
  89. package/src/inventory/products/product.module.d.ts +4 -0
  90. package/src/inventory/products/product.module.ts +16 -0
  91. package/src/inventory/products/product.repository.d.ts +18 -0
  92. package/src/inventory/products/product.repository.ts +94 -0
  93. package/src/inventory/products/variants/variant.controller.d.ts +7 -0
  94. package/src/inventory/products/variants/variant.controller.ts +23 -0
  95. package/src/inventory/products/variants/variant.module.d.ts +4 -0
  96. package/src/inventory/products/variants/variant.module.ts +14 -0
  97. package/src/inventory/products/variants/variant.repository.d.ts +10 -0
  98. package/src/inventory/products/variants/variant.repository.ts +23 -0
  99. package/src/inventory/properties/property.controller.d.ts +11 -0
  100. package/src/inventory/properties/property.controller.ts +42 -0
  101. package/src/inventory/properties/property.module.d.ts +4 -0
  102. package/src/inventory/properties/property.module.ts +14 -0
  103. package/src/inventory/properties/property.repository.d.ts +13 -0
  104. package/src/inventory/properties/property.repository.ts +38 -0
  105. package/src/store/carts/cart.controller.d.ts +11 -0
  106. package/src/store/carts/cart.controller.ts +44 -0
  107. package/src/store/carts/cart.module.d.ts +4 -0
  108. package/src/store/carts/cart.module.ts +14 -0
  109. package/src/store/carts/cart.repository.d.ts +13 -0
  110. package/src/store/carts/cart.repository.ts +36 -0
  111. package/src/store/orders/items/item.controller.d.ts +11 -0
  112. package/src/store/orders/items/item.controller.ts +41 -0
  113. package/src/store/orders/items/item.module.d.ts +4 -0
  114. package/src/store/orders/items/item.module.ts +14 -0
  115. package/src/store/orders/items/item.repository.d.ts +13 -0
  116. package/src/store/orders/items/item.repository.ts +35 -0
  117. package/src/store/orders/order.controller.d.ts +11 -0
  118. package/src/store/orders/order.controller.ts +44 -0
  119. package/src/store/orders/order.module.d.ts +4 -0
  120. package/src/store/orders/order.module.ts +15 -0
  121. package/src/store/orders/order.repository.d.ts +13 -0
  122. package/src/store/orders/order.repository.ts +35 -0
  123. package/src/store/store.module.d.ts +4 -0
  124. package/src/store/store.module.ts +14 -0
  125. package/src/app.ts +0 -40
package/src/app.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { EventEmitter2 } from '@nestjs/event-emitter';
2
+ import { event, eventNS } from 'eventemitter2';
3
+ export declare enum AbstractEvent {
4
+ ENTITY_LISTED = "entity.*.listed",
5
+ ENTITY_READED = "entity.*.readed",
6
+ ENTITY_CREATED = "entity.*.created",
7
+ ENTITY_UPDATED = "entity.*.updated",
8
+ ENTITY_DELETED = "entity.*.deleted",
9
+ ENTITY_NOT_FOUND = "entity.*.not_found",
10
+ ENTITY_SYNCED = "entity.*.synced"
11
+ }
12
+ export default class AppEmitter {
13
+ protected readonly emitter: EventEmitter2;
14
+ emit(event: event | eventNS, ...values: any[]): boolean;
15
+ private handleAllEvents;
16
+ }
@@ -0,0 +1,27 @@
1
+ import { Inject, Injectable, Logger } from '@nestjs/common'
2
+ import { EventEmitter2, OnEvent } from '@nestjs/event-emitter'
3
+ import { event, eventNS } from 'eventemitter2'
4
+
5
+ export enum AbstractEvent {
6
+ ENTITY_LISTED = 'entity.*.listed',
7
+ ENTITY_READED = 'entity.*.readed',
8
+ ENTITY_CREATED = 'entity.*.created',
9
+ ENTITY_UPDATED = 'entity.*.updated',
10
+ ENTITY_DELETED = 'entity.*.deleted',
11
+ ENTITY_NOT_FOUND = 'entity.*.not_found',
12
+ ENTITY_SYNCED = 'entity.*.synced',
13
+ }
14
+
15
+ @Injectable()
16
+ export default class AppEmitter {
17
+ @Inject() protected readonly emitter: EventEmitter2
18
+
19
+ public emit (event: event | eventNS, ...values: any[]) {
20
+ return this.emitter.emit(event, values)
21
+ }
22
+
23
+ @OnEvent('*.*.*')
24
+ private handleAllEvents (payload: any, name: string) {
25
+ return Logger.debug(`Event '${name}' has emitted an ${typeof payload}`, AppEmitter.name)
26
+ }
27
+ }
@@ -0,0 +1,7 @@
1
+ import { TransformFnParams } from 'class-transformer';
2
+ import { IEntity } from 'fireorm';
3
+ export default abstract class AppEntity implements IEntity {
4
+ static readonly $path: string;
5
+ id: string;
6
+ static transformSubCollection({ value }: TransformFnParams): string;
7
+ }
@@ -0,0 +1,9 @@
1
+ import { MiddlewareConsumer, ModuleMetadata, NestMiddleware, NestModule } from '@nestjs/common';
2
+ import { NextFunction, Request, Response } from 'express';
3
+ export declare const metadata: ModuleMetadata;
4
+ export default class AppModule implements NestModule {
5
+ configure(consumer: MiddlewareConsumer): MiddlewareConsumer;
6
+ }
7
+ export declare class LoggerMiddleware implements NestMiddleware {
8
+ use(request: Request, response: Response, next: NextFunction): Promise<void>;
9
+ }
@@ -0,0 +1,45 @@
1
+ import { Logger, MiddlewareConsumer, Module, ModuleMetadata, NestMiddleware, NestModule } from '@nestjs/common'
2
+ import { ConfigModule } from '@nestjs/config'
3
+ import { RouterModule } from '@nestjs/core'
4
+ import { EventEmitterModule } from '@nestjs/event-emitter'
5
+ import { NextFunction, Request, Response } from 'express'
6
+ import AccountModule from './account/account.module'
7
+ import AuthModule from './account/auth/auth.module'
8
+ // import AppConfig from './app.config'
9
+ import AppEmitter from './app.emitter'
10
+ import AppRoutes from './app.routes'
11
+ // import InventoryModule from './inventory/inventory.module'
12
+ // import StoreModule from './store/store.module'
13
+
14
+ const modules = [
15
+ ConfigModule.forRoot({ isGlobal: true }),
16
+ EventEmitterModule.forRoot({ wildcard: true }),
17
+ RouterModule.register(AppRoutes),
18
+ AuthModule,
19
+ // InventoryModule,
20
+ // StoreModule,
21
+ AccountModule
22
+ ]
23
+
24
+ export const metadata: ModuleMetadata = {
25
+ imports: modules,
26
+ providers: [AppEmitter]
27
+ }
28
+
29
+ @Module(metadata)
30
+ export default class AppModule implements NestModule {
31
+ configure (consumer: MiddlewareConsumer): MiddlewareConsumer {
32
+
33
+ return consumer
34
+ .apply(LoggerMiddleware).forRoutes('/')
35
+ }
36
+ }
37
+
38
+ export class LoggerMiddleware implements NestMiddleware {
39
+ async use (request: Request, response: Response, next: NextFunction): Promise<void> {
40
+ await next()
41
+ const referer = new URL(request.header('referer') || 'http://localhost').host
42
+
43
+ return Logger.log(`[${referer}] ${response.statusCode} ${request.method} ${request.url}`, LoggerMiddleware.name)
44
+ }
45
+ }
@@ -0,0 +1,5 @@
1
+ import { BaseFirestoreRepository, IEntity } from 'fireorm';
2
+ export default abstract class AppRepository {
3
+ protected abstract readonly repositories: Record<string, BaseFirestoreRepository<IEntity>>;
4
+ static setReference($path: string, value: string): Promise<any>;
5
+ }
@@ -0,0 +1,12 @@
1
+ import { BaseFirestoreRepository, IEntity } from 'fireorm'
2
+ import { firestore } from 'firebase-admin'
3
+
4
+ export default abstract class AppRepository {
5
+ protected abstract readonly repositories: Record<string, BaseFirestoreRepository<IEntity>>
6
+
7
+ public static async setReference ($path: string, value: string): Promise<any> {
8
+ const { ref } = await firestore().collection($path).doc(value).get()
9
+
10
+ return ref
11
+ }
12
+ }
@@ -0,0 +1,3 @@
1
+ import { RouteTree } from '@nestjs/core/router/interfaces/routes.interface';
2
+ declare const routes: RouteTree[];
3
+ export default routes;
@@ -0,0 +1,61 @@
1
+ import { RouteTree } from '@nestjs/core/router/interfaces/routes.interface'
2
+ import { $AccountPath, OrganizationEntity, RoleEntity, UserEntity } from './account'
3
+ import AccountModule from './account/account.module'
4
+ import { $AuthPath as AccountAuthPath } from './account/auth'
5
+ import AuthModule from './account/auth/auth.module'
6
+ import MemberModule from './account/organizations/members/member.module'
7
+ import OrganizationModule from './account/organizations/organization.module'
8
+ import RoleModule from './account/roles/role.module'
9
+ import RoleUserModule from './account/roles/users/user.module'
10
+ import UserRoleModule from './account/users/roles/role.module'
11
+ import UserModule from './account/users/user.module'
12
+ import { $InventoryPath, ProductEntity } from './inventory'
13
+ import BrandModule from './inventory/brands/brand.module'
14
+ import CategoryModule from './inventory/categories/category.module'
15
+ import InventoryModule from './inventory/inventory.module'
16
+ import MediaModule from './inventory/products/media/media.module'
17
+ import ProductModule from './inventory/products/product.module'
18
+ import VariantModule from './inventory/products/variants/variant.module'
19
+ import PropertyModule from './inventory/properties/property.module'
20
+ import { $StorePath, OrderEntity } from './store'
21
+ import CartModule from './store/carts/cart.module'
22
+ import ItemModule from './store/orders/items/item.module'
23
+ import OrderModule from './store/orders/order.module'
24
+ import StoreModule from './store/store.module'
25
+
26
+ const addModule = (module, children = [], path = '/'): RouteTree => ({ path, module, children })
27
+
28
+ const routes = [
29
+ addModule(AuthModule, [], AccountAuthPath),
30
+
31
+ addModule(AccountModule, [
32
+ addModule(UserModule, [
33
+ addModule(UserRoleModule, [], UserEntity.$path)
34
+ ]),
35
+ addModule(OrganizationModule, [
36
+ addModule(MemberModule, [], OrganizationEntity.$path)
37
+ ]),
38
+ addModule(RoleModule, [
39
+ addModule(RoleUserModule, [], RoleEntity.$path)
40
+ ])
41
+ ], $AccountPath),
42
+
43
+ addModule(InventoryModule, [
44
+ addModule(BrandModule),
45
+ addModule(CategoryModule),
46
+ addModule(PropertyModule),
47
+ addModule(ProductModule, [
48
+ addModule(VariantModule, [], ProductEntity.$path),
49
+ addModule(MediaModule, [], ProductEntity.$path)
50
+ ])
51
+ ], $InventoryPath),
52
+
53
+ addModule(StoreModule, [
54
+ addModule(CartModule),
55
+ addModule(OrderModule, [
56
+ addModule(ItemModule, [], OrderEntity.$path)
57
+ ])
58
+ ], $StorePath)
59
+ ]
60
+
61
+ export default routes
@@ -0,0 +1,11 @@
1
+ import { BrandEntity } from './brand.entity';
2
+ import BrandRepository from './brand.repository';
3
+ import { CreateBrandValidator, UpdateBrandValidator } from './brand.validator';
4
+ export default class BrandController {
5
+ protected readonly repository: BrandRepository;
6
+ find(): Promise<BrandEntity[]>;
7
+ read(id: string): Promise<BrandEntity>;
8
+ create(validator: CreateBrandValidator): Promise<BrandEntity>;
9
+ update(id: string, validator: UpdateBrandValidator): Promise<BrandEntity>;
10
+ delete(id: string): Promise<void>;
11
+ }
@@ -0,0 +1,41 @@
1
+ import { Body, Controller, Delete, Get, HttpCode, Inject, Param, Post, Put } from '@nestjs/common'
2
+ import { ApiTags } from '@nestjs/swagger'
3
+ import { BrandEntity } from './brand.entity'
4
+ import BrandRepository from './brand.repository'
5
+ import { CreateBrandValidator, UpdateBrandValidator } from './brand.validator'
6
+
7
+ @Controller(BrandEntity.$path)
8
+ @ApiTags(BrandController.name)
9
+ export default class BrandController {
10
+ @Inject() protected readonly repository: BrandRepository
11
+
12
+ @Get('/')
13
+ async find (): Promise<BrandEntity[]> {
14
+
15
+ return this.repository.find()
16
+ }
17
+
18
+ @Get('/:id')
19
+ async read (@Param('id') id: string): Promise<BrandEntity> {
20
+ return this.repository.read(id)
21
+ }
22
+
23
+ @Post('/')
24
+ @HttpCode(201)
25
+ async create (@Body() validator: CreateBrandValidator): Promise<BrandEntity> {
26
+
27
+ return this.repository.create(validator)
28
+ }
29
+
30
+ @Put('/:id')
31
+ async update (@Param('id') id: string, @Body() validator: UpdateBrandValidator): Promise<BrandEntity> {
32
+
33
+ return this.repository.update(id, validator)
34
+ }
35
+
36
+ @Delete('/:id')
37
+ @HttpCode(204)
38
+ async delete (@Param('id') id: string): Promise<void> {
39
+ return this.repository.delete(id)
40
+ }
41
+ }
@@ -0,0 +1,4 @@
1
+ import { ModuleMetadata } from '@nestjs/common';
2
+ export declare const metadata: ModuleMetadata;
3
+ export default class BrandModule {
4
+ }
@@ -0,0 +1,14 @@
1
+ import { Module, ModuleMetadata } from '@nestjs/common'
2
+ import BrandController from './brand.controller'
3
+ import BrandRepository from './brand.repository'
4
+
5
+ export const metadata: ModuleMetadata = {
6
+ imports: [],
7
+ controllers: [BrandController],
8
+ providers: [BrandRepository],
9
+ exports: []
10
+ }
11
+
12
+ @Module(metadata)
13
+ export default class BrandModule {
14
+ }
@@ -0,0 +1,13 @@
1
+ import AppRepository from '../../app.repository';
2
+ import { BrandEntity } from './brand.entity';
3
+ import { CreateBrandValidator, UpdateBrandValidator } from './brand.validator';
4
+ export default class BrandRepository extends AppRepository {
5
+ protected readonly repositories: {
6
+ brand: import("fireorm").BaseFirestoreRepository<BrandEntity>;
7
+ };
8
+ find(): Promise<BrandEntity[]>;
9
+ read(id: string): Promise<BrandEntity>;
10
+ create(validator: CreateBrandValidator): Promise<BrandEntity>;
11
+ update(id: any, validator: UpdateBrandValidator): Promise<BrandEntity>;
12
+ delete(id: string): Promise<void>;
13
+ }
@@ -0,0 +1,36 @@
1
+ import { getRepository } from 'fireorm'
2
+ import AppRepository from '../../app.repository'
3
+ import { BrandEntity } from './brand.entity'
4
+ import { CreateBrandValidator, UpdateBrandValidator } from './brand.validator'
5
+
6
+ export default class BrandRepository extends AppRepository {
7
+ protected readonly repositories = {
8
+ brand: getRepository(BrandEntity)
9
+ }
10
+
11
+ public find () {
12
+ return this.repositories.brand.find()
13
+ }
14
+
15
+ public read (id: string) {
16
+ return this.repositories.brand.findById(id)
17
+ }
18
+
19
+ public create (validator: CreateBrandValidator) {
20
+ const brand = new BrandEntity()
21
+ brand.name = validator.name
22
+
23
+ return this.repositories.brand.create(brand)
24
+ }
25
+
26
+ public update (id, validator: UpdateBrandValidator) {
27
+ const brand = <BrandEntity>{}
28
+ brand.name = validator.name
29
+
30
+ return this.repositories.brand.update(brand)
31
+ }
32
+
33
+ public delete (id: string) {
34
+ return this.repositories.brand.delete(id)
35
+ }
36
+ }
@@ -0,0 +1,11 @@
1
+ import { CategoryEntity } from './category.entity';
2
+ import CategoryRepository from './category.repository';
3
+ import { CreateCategoryValidator, UpdateCategoryValidator } from './category.validator';
4
+ export default class CategoryController {
5
+ protected readonly repository: CategoryRepository;
6
+ find(): Promise<CategoryEntity[]>;
7
+ read(id: string): Promise<CategoryEntity>;
8
+ create(validator: CreateCategoryValidator): Promise<CategoryEntity>;
9
+ update(id: string, validator: UpdateCategoryValidator): Promise<CategoryEntity>;
10
+ delete(id: string): Promise<void>;
11
+ }
@@ -0,0 +1,43 @@
1
+ import { Body, Controller, Delete, Get, HttpCode, Inject, Param, Post, Put } from '@nestjs/common'
2
+ import { ApiTags } from '@nestjs/swagger'
3
+ import { CategoryEntity } from './category.entity'
4
+ import CategoryRepository from './category.repository'
5
+ import { CreateCategoryValidator, UpdateCategoryValidator } from './category.validator'
6
+
7
+ @Controller(CategoryEntity.$path)
8
+ @ApiTags(CategoryController.name)
9
+ export default class CategoryController {
10
+ @Inject() protected readonly repository: CategoryRepository
11
+
12
+ @Get('/')
13
+ async find (): Promise<CategoryEntity[]> {
14
+
15
+ return this.repository.find()
16
+ }
17
+
18
+ @Get('/:id')
19
+ async read (@Param('id') id: string): Promise<CategoryEntity> {
20
+
21
+ return this.repository.read(id)
22
+ }
23
+
24
+ @Post('/')
25
+ @HttpCode(201)
26
+ async create (@Body() validator: CreateCategoryValidator): Promise<CategoryEntity> {
27
+
28
+ return this.repository.create(validator)
29
+ }
30
+
31
+ @Put('/:id')
32
+ async update (@Param('id') id: string, @Body() validator: UpdateCategoryValidator): Promise<CategoryEntity> {
33
+
34
+ return this.repository.update(id, validator)
35
+ }
36
+
37
+ @Delete('/:id')
38
+ @HttpCode(204)
39
+ async delete (@Param('id') id: string): Promise<void> {
40
+
41
+ return this.repository.delete(id)
42
+ }
43
+ }
@@ -0,0 +1,4 @@
1
+ import { ModuleMetadata } from '@nestjs/common';
2
+ export declare const metadata: ModuleMetadata;
3
+ export default class CategoryModule {
4
+ }
@@ -0,0 +1,14 @@
1
+ import { Module, ModuleMetadata } from '@nestjs/common'
2
+ import CategoryController from './category.controller'
3
+ import CategoryRepository from './category.repository'
4
+
5
+ export const metadata: ModuleMetadata = {
6
+ imports: [],
7
+ controllers: [CategoryController],
8
+ providers: [CategoryRepository],
9
+ exports: []
10
+ }
11
+
12
+ @Module(metadata)
13
+ export default class CategoryModule {
14
+ }
@@ -0,0 +1,13 @@
1
+ import AppRepository from '../../app.repository';
2
+ import { CategoryEntity } from './category.entity';
3
+ import { CreateCategoryValidator, UpdateCategoryValidator } from './category.validator';
4
+ export default class CategoryRepository extends AppRepository {
5
+ protected readonly repositories: {
6
+ category: import("fireorm").BaseFirestoreRepository<CategoryEntity>;
7
+ };
8
+ find(): Promise<CategoryEntity[]>;
9
+ read(id: string): Promise<CategoryEntity>;
10
+ create(validator: CreateCategoryValidator): Promise<CategoryEntity>;
11
+ update(id: any, validator: UpdateCategoryValidator): Promise<CategoryEntity>;
12
+ delete(id: string): Promise<void>;
13
+ }
@@ -0,0 +1,36 @@
1
+ import { getRepository } from 'fireorm'
2
+ import AppRepository from '../../app.repository'
3
+ import { CategoryEntity } from './category.entity'
4
+ import { CreateCategoryValidator, UpdateCategoryValidator } from './category.validator'
5
+
6
+ export default class CategoryRepository extends AppRepository {
7
+ protected readonly repositories = {
8
+ category: getRepository(CategoryEntity)
9
+ }
10
+
11
+ public find () {
12
+ return this.repositories.category.find()
13
+ }
14
+
15
+ public read (id: string) {
16
+ return this.repositories.category.findById(id)
17
+ }
18
+
19
+ public create (validator: CreateCategoryValidator) {
20
+ const category = new CategoryEntity()
21
+ category.name = validator.name
22
+
23
+ return this.repositories.category.create(category)
24
+ }
25
+
26
+ public update (id, validator: UpdateCategoryValidator) {
27
+ const category = <CategoryEntity>{}
28
+ category.name = validator.name
29
+
30
+ return this.repositories.category.update(category)
31
+ }
32
+
33
+ public delete (id: string) {
34
+ return this.repositories.category.delete(id)
35
+ }
36
+ }
@@ -0,0 +1,4 @@
1
+ import { ModuleMetadata } from '@nestjs/common';
2
+ export declare const metadata: ModuleMetadata;
3
+ export default class InventoryModule {
4
+ }
@@ -0,0 +1,17 @@
1
+ import { Module, ModuleMetadata } from '@nestjs/common'
2
+ import BrandModule from './brands/brand.module'
3
+ import CategoryModule from './categories/category.module'
4
+ import ProductModule from './products/product.module'
5
+ import PropertyModule from './properties/property.module'
6
+
7
+ export const metadata: ModuleMetadata = {
8
+ imports: [BrandModule, CategoryModule, ProductModule, PropertyModule],
9
+ controllers: [],
10
+ providers: [],
11
+ exports: []
12
+ }
13
+
14
+ @Module(metadata)
15
+ export default class InventoryModule {
16
+
17
+ }
@@ -0,0 +1,7 @@
1
+ import { ProductMediaEntity } from './media.entity';
2
+ import MediaRepository from './media.repository';
3
+ export default class MediaController {
4
+ protected readonly repository: MediaRepository;
5
+ find(productId: string): Promise<ProductMediaEntity[]>;
6
+ read(productId: string, id: string): Promise<ProductMediaEntity | null>;
7
+ }
@@ -0,0 +1,23 @@
1
+ import { Controller, Get, Inject, Param } from '@nestjs/common'
2
+ import { ApiTags } from '@nestjs/swagger'
3
+ import { ProductMediaEntity } from './media.entity'
4
+ import MediaRepository from './media.repository'
5
+
6
+ @Controller(':product/media')
7
+ @ApiTags(MediaController.name)
8
+ export default class MediaController {
9
+ @Inject() protected readonly repository: MediaRepository
10
+
11
+ @Get('/')
12
+ async find (@Param('product') productId: string): Promise<ProductMediaEntity[]> {
13
+
14
+ return this.repository.find(productId)
15
+ }
16
+
17
+ @Get('/:id')
18
+ async read (@Param('product') productId: string, @Param('id') id: string): Promise<ProductMediaEntity | null> {
19
+
20
+ return this.repository.read(productId, id)
21
+ }
22
+
23
+ }
@@ -0,0 +1,4 @@
1
+ import { ModuleMetadata } from '@nestjs/common';
2
+ export declare const metadata: ModuleMetadata;
3
+ export default class MediaModule {
4
+ }
@@ -0,0 +1,14 @@
1
+ import { Module, ModuleMetadata } from '@nestjs/common'
2
+ import MediaController from './media.controller'
3
+ import MediaRepository from './media.repository'
4
+
5
+ export const metadata: ModuleMetadata = {
6
+ imports: [],
7
+ controllers: [MediaController],
8
+ providers: [MediaRepository],
9
+ exports: []
10
+ }
11
+
12
+ @Module(metadata)
13
+ export default class MediaModule {
14
+ }
@@ -0,0 +1,10 @@
1
+ import AppRepository from '../../../app.repository';
2
+ import { ProductEntity } from '../product.entity';
3
+ import { ProductMediaEntity } from './media.entity';
4
+ export default class MediaRepository extends AppRepository {
5
+ protected readonly repositories: {
6
+ product: import("fireorm").BaseFirestoreRepository<ProductEntity>;
7
+ };
8
+ find(productID: string): Promise<ProductMediaEntity[]>;
9
+ read(productID: string, id: string): Promise<ProductMediaEntity>;
10
+ }
@@ -0,0 +1,22 @@
1
+ import { getRepository } from 'fireorm'
2
+ import AppRepository from '../../../app.repository'
3
+ import { ProductEntity } from '../product.entity'
4
+ import { ProductMediaEntity } from './media.entity'
5
+
6
+ export default class MediaRepository extends AppRepository {
7
+ protected readonly repositories = {
8
+ product: getRepository(ProductEntity)
9
+ }
10
+
11
+ async find (productID: string): Promise<ProductMediaEntity[]> {
12
+ const product = await this.repositories.product.findById(productID)
13
+
14
+ return product.media.find()
15
+ }
16
+
17
+ async read (productID: string, id: string): Promise<ProductMediaEntity> {
18
+ const product = await this.repositories.product.findById(productID)
19
+
20
+ return product.media.findById(id)
21
+ }
22
+ }
@@ -0,0 +1,12 @@
1
+ /// <reference types="@types/multer" />
2
+ import { ProductEntity } from './product.entity';
3
+ import ProductRepository from './product.repository';
4
+ import { CreateProductValidator, UpdateProductValidator } from './product.validator';
5
+ export default class ProductController {
6
+ protected readonly repository: ProductRepository;
7
+ find(): Promise<ProductEntity[]>;
8
+ create(validator: CreateProductValidator, images: Express.Multer.File[]): Promise<ProductEntity>;
9
+ read(id: string): Promise<ProductEntity>;
10
+ update(validator: UpdateProductValidator, id: string): Promise<ProductEntity>;
11
+ delete(id: string): Promise<void>;
12
+ }
@@ -0,0 +1,59 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ Delete,
5
+ Get,
6
+ HttpCode,
7
+ Inject,
8
+ Param,
9
+ Patch,
10
+ Post,
11
+ UploadedFiles,
12
+ UseInterceptors
13
+ } from '@nestjs/common'
14
+ import { FilesInterceptor } from '@nestjs/platform-express'
15
+ import { ApiTags } from '@nestjs/swagger'
16
+ import { Express } from 'express'
17
+ import { ProductEntity } from './product.entity'
18
+ import ProductRepository from './product.repository'
19
+ import { CreateProductValidator, UpdateProductValidator } from './product.validator'
20
+
21
+ @Controller(ProductEntity.$path)
22
+ @ApiTags(ProductController.name)
23
+ export default class ProductController {
24
+ @Inject() protected readonly repository: ProductRepository
25
+
26
+ @Get('/')
27
+ async find (): Promise<ProductEntity[]> {
28
+
29
+ return this.repository.find()
30
+ }
31
+
32
+ @Post('/')
33
+ @UseInterceptors(FilesInterceptor('images'))
34
+ async create (@Body() validator: CreateProductValidator, @UploadedFiles() images: Express.Multer.File[]): Promise<ProductEntity> {
35
+
36
+ return this.repository.create(validator, images)
37
+ }
38
+
39
+ @Get('/:id')
40
+ async read (@Param('id') id: string): Promise<ProductEntity> {
41
+
42
+ return this.repository.read(id)
43
+ }
44
+
45
+ @Patch('/:id')
46
+ @UseInterceptors(FilesInterceptor('images'))
47
+ async update (@Body() validator: UpdateProductValidator, @Param('id') id: string): Promise<ProductEntity> {
48
+
49
+ return this.repository.update(id, validator)
50
+ }
51
+
52
+ @Delete('/:id')
53
+ @HttpCode(204)
54
+ async delete (@Param('id') id: string): Promise<void> {
55
+
56
+ return this.repository.delete(id)
57
+ }
58
+
59
+ }
@@ -0,0 +1,4 @@
1
+ import { ModuleMetadata } from '@nestjs/common';
2
+ export declare const metadata: ModuleMetadata;
3
+ export default class ProductModule {
4
+ }