@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.
- package/.output/abstracts/abstract.entity.d.ts +14 -0
- package/.output/abstracts/abstract.validator.d.ts +24 -0
- package/.output/abstracts/abstract.validator.js +118 -0
- package/.output/exceptions/missing-identity.exception.d.ts +5 -0
- package/.output/exceptions/missing-identity.exception.js +30 -0
- package/.output/modules/asset/files/file.entity.d.ts +9 -0
- package/.output/modules/asset/files/file.schema.d.ts +34 -0
- package/.output/modules/asset/files/file.schema.js +10 -0
- package/.output/modules/auth/organizations/organization.entity.d.ts +8 -0
- package/.output/modules/auth/users/user.entity.d.ts +9 -0
- package/.output/modules/auth/users/user.schema.d.ts +34 -0
- package/.output/modules/auth/users/user.schema.js +10 -0
- package/.output/modules/auth/users/user.validator.d.ts +12 -0
- package/.output/modules/auth/users/user.validator.js +58 -0
- package/.output/modules/inventory/brands/brand.entity.d.ts +6 -0
- package/.output/modules/inventory/brands/brand.schema.d.ts +34 -0
- package/.output/modules/inventory/brands/brand.schema.js +10 -0
- package/.output/modules/inventory/brands/brand.validator.d.ts +11 -0
- package/.output/modules/inventory/brands/brand.validator.js +74 -0
- package/.output/modules/inventory/categories/category.entity.d.ts +6 -0
- package/.output/modules/inventory/categories/category.schema.d.ts +34 -0
- package/.output/modules/inventory/categories/category.schema.js +10 -0
- package/.output/modules/inventory/categories/category.validator.d.ts +8 -0
- package/.output/modules/inventory/categories/category.validator.js +42 -0
- package/.output/modules/inventory/complements/complement.entity.d.ts +6 -0
- package/.output/modules/inventory/complements/complement.validator.d.ts +10 -0
- package/.output/modules/inventory/complements/complement.validator.js +52 -0
- package/.output/modules/inventory/products/documents/attribute.document.d.ts +5 -0
- package/.output/modules/inventory/products/documents/attribute.document.js +33 -0
- package/.output/modules/inventory/products/documents/dimension.document.d.ts +6 -0
- package/.output/modules/inventory/products/documents/dimension.document.js +35 -0
- package/.output/modules/inventory/products/product.entity.d.ts +19 -0
- package/.output/modules/inventory/products/product.schema.d.ts +34 -0
- package/.output/modules/inventory/products/product.schema.js +18 -0
- package/.output/modules/inventory/products/product.validator.d.ts +29 -0
- package/.output/modules/inventory/products/product.validator.js +179 -0
- package/.output/modules/inventory/products/validators/attributes.validator.d.ts +5 -0
- package/.output/modules/inventory/products/validators/attributes.validator.js +35 -0
- package/.output/modules/inventory/products/validators/dimension.validator.d.ts +6 -0
- package/.output/modules/inventory/products/validators/dimension.validator.js +38 -0
- package/.output/modules/sale/customers/customer.entity.d.ts +8 -0
- package/.output/modules/sale/customers/customer.schema.d.ts +34 -0
- package/.output/modules/sale/customers/customer.schema.js +10 -0
- package/.output/modules/sale/customers/customer.validator.d.ts +14 -0
- package/.output/modules/sale/customers/customer.validator.js +94 -0
- package/.output/modules/sale/orders/documents/address.document.d.ts +8 -0
- package/.output/modules/sale/orders/documents/address.document.js +43 -0
- package/.output/modules/sale/orders/documents/status.document.d.ts +8 -0
- package/.output/modules/sale/orders/documents/status.document.js +34 -0
- package/.output/modules/sale/orders/entities/item.entity.d.ts +38 -0
- package/.output/modules/sale/orders/enums/order.status.d.ts +6 -0
- package/.output/modules/sale/orders/enums/order.status.js +10 -0
- package/.output/modules/sale/orders/order.entity.d.ts +21 -0
- package/.output/modules/sale/orders/order.validator.d.ts +16 -0
- package/.output/modules/sale/orders/order.validator.js +86 -0
- package/.output/modules/sale/orders/validators/address.validator.d.ts +17 -0
- package/.output/modules/sale/orders/validators/address.validator.js +81 -0
- package/{src/modules/sale/orders/validators/billing.validator.ts → .output/modules/sale/orders/validators/billing.validator.d.ts} +4 -7
- package/.output/modules/sale/orders/validators/billing.validator.js +13 -0
- package/.output/modules/sale/orders/validators/item.validator.d.ts +5 -0
- package/.output/modules/sale/orders/validators/item.validator.js +32 -0
- package/.output/modules/sale/orders/validators/payment.validator.d.ts +10 -0
- package/.output/modules/sale/orders/validators/payment.validator.js +62 -0
- package/.output/modules/sale/orders/validators/shipping.validator.d.ts +9 -0
- package/.output/modules/sale/orders/validators/shipping.validator.js +14 -0
- package/.output/modules/sale/payments/entities/status.entity.d.ts +8 -0
- package/.output/modules/sale/payments/enums/billing.type.d.ts +6 -0
- package/.output/modules/sale/payments/enums/billing.type.js +10 -0
- package/.output/modules/sale/payments/enums/payment.status.d.ts +7 -0
- package/.output/modules/sale/payments/enums/payment.status.js +11 -0
- package/.output/modules/sale/payments/enums/shipping.type.d.ts +4 -0
- package/.output/modules/sale/payments/enums/shipping.type.js +8 -0
- package/.output/modules/sale/payments/payment.entity.d.ts +12 -0
- package/.output/modules/sale/payments/payment.schema.d.ts +34 -0
- package/.output/modules/sale/payments/payment.schema.js +14 -0
- package/.output/modules/sale/payments/payment.validator.d.ts +16 -0
- package/.output/modules/sale/payments/payment.validator.js +77 -0
- package/.output/tsconfig.package.tsbuildinfo +1 -0
- package/package.json +4 -1
- package/.bin/deploy.sh +0 -9
- package/.bin/package.sh +0 -12
- package/.docker/Dockerfile +0 -21
- package/.dockerignore +0 -12
- package/.github/dependabot.yml +0 -17
- package/.github/semantic.yml +0 -5
- package/.github/workflows/pull_request.yml +0 -35
- package/.prettierrc +0 -5
- package/app.ts +0 -11
- package/authCertificate.pem +0 -19
- package/nest-cli.json +0 -8
- package/src/abstracts/abstarct.repository.ts +0 -62
- package/src/abstracts/abstract.controller.ts +0 -18
- package/src/abstracts/abstract.entity.ts +0 -22
- package/src/abstracts/abstract.router.ts +0 -7
- package/src/abstracts/abstract.validator.ts +0 -61
- package/src/app.config.ts +0 -59
- package/src/app.console.ts +0 -24
- package/src/app.guard.ts +0 -39
- package/src/app.module.ts +0 -54
- package/src/app.strategy.ts +0 -21
- package/src/commands/seed.command.ts +0 -263
- package/src/decorators/public.decorator.ts +0 -5
- package/src/decorators/user.decorator.ts +0 -30
- package/src/exceptions/missing-identity.exception.ts +0 -11
- package/src/interceptors/mongoose.interceptor.ts +0 -63
- package/src/main.ts +0 -27
- package/src/middlewares/router.middleware.ts +0 -14
- package/src/modules/asset/asset.module.ts +0 -19
- package/src/modules/asset/files/file.controller.ts +0 -22
- package/src/modules/asset/files/file.entity.ts +0 -24
- package/src/modules/asset/files/file.module.ts +0 -21
- package/src/modules/asset/files/file.repository.ts +0 -44
- package/src/modules/asset/files/file.schema.ts +0 -8
- package/src/modules/asset/files/file.service.ts +0 -4
- package/src/modules/auth/auth.controller.ts +0 -57
- package/src/modules/auth/auth.module.ts +0 -20
- package/src/modules/auth/organizations/organization.controller.ts +0 -20
- package/src/modules/auth/organizations/organization.entity.ts +0 -22
- package/src/modules/auth/organizations/organization.module.ts +0 -21
- package/src/modules/auth/organizations/organization.repository.ts +0 -16
- package/src/modules/auth/organizations/organization.schema.ts +0 -8
- package/src/modules/auth/users/user.controller.ts +0 -23
- package/src/modules/auth/users/user.entity.ts +0 -25
- package/src/modules/auth/users/user.module.ts +0 -20
- package/src/modules/auth/users/user.repository.ts +0 -79
- package/src/modules/auth/users/user.schema.ts +0 -8
- package/src/modules/auth/users/user.validator.ts +0 -32
- package/src/modules/command.module.ts +0 -15
- package/src/modules/global.module.ts +0 -46
- package/src/modules/inventory/brands/brand.controller.ts +0 -44
- package/src/modules/inventory/brands/brand.entity.ts +0 -20
- package/src/modules/inventory/brands/brand.module.ts +0 -20
- package/src/modules/inventory/brands/brand.repository.ts +0 -40
- package/src/modules/inventory/brands/brand.schema.ts +0 -8
- package/src/modules/inventory/brands/brand.validator.ts +0 -31
- package/src/modules/inventory/categories/category.controller.ts +0 -42
- package/src/modules/inventory/categories/category.entity.ts +0 -15
- package/src/modules/inventory/categories/category.module.ts +0 -19
- package/src/modules/inventory/categories/category.repository.ts +0 -34
- package/src/modules/inventory/categories/category.schema.ts +0 -8
- package/src/modules/inventory/categories/category.validator.ts +0 -20
- package/src/modules/inventory/complements/complement.controller.ts +0 -41
- package/src/modules/inventory/complements/complement.entity.ts +0 -15
- package/src/modules/inventory/complements/complement.module.ts +0 -19
- package/src/modules/inventory/complements/complement.repository.ts +0 -37
- package/src/modules/inventory/complements/complement.schema.ts +0 -8
- package/src/modules/inventory/complements/complement.validator.ts +0 -28
- package/src/modules/inventory/inventory.module.ts +0 -23
- package/src/modules/inventory/products/documents/attribute.document.ts +0 -14
- package/src/modules/inventory/products/documents/dimension.document.ts +0 -16
- package/src/modules/inventory/products/product.controller.ts +0 -62
- package/src/modules/inventory/products/product.entity.ts +0 -46
- package/src/modules/inventory/products/product.module.ts +0 -19
- package/src/modules/inventory/products/product.repository.ts +0 -64
- package/src/modules/inventory/products/product.schema.ts +0 -19
- package/src/modules/inventory/products/product.validator.ts +0 -132
- package/src/modules/inventory/products/validators/attributes.validator.ts +0 -15
- package/src/modules/inventory/products/validators/dimension.validator.ts +0 -19
- package/src/modules/sale/customers/customer.controller.ts +0 -41
- package/src/modules/sale/customers/customer.entity.ts +0 -19
- package/src/modules/sale/customers/customer.module.ts +0 -18
- package/src/modules/sale/customers/customer.repository.ts +0 -30
- package/src/modules/sale/customers/customer.schema.ts +0 -8
- package/src/modules/sale/customers/customer.validator.ts +0 -43
- package/src/modules/sale/orders/documents/address.document.ts +0 -22
- package/src/modules/sale/orders/documents/status.document.ts +0 -17
- package/src/modules/sale/orders/entities/item.entity.ts +0 -24
- package/src/modules/sale/orders/enums/order.status.ts +0 -6
- package/src/modules/sale/orders/order.controller.ts +0 -65
- package/src/modules/sale/orders/order.entity.ts +0 -46
- package/src/modules/sale/orders/order.module.ts +0 -22
- package/src/modules/sale/orders/order.repository.ts +0 -122
- package/src/modules/sale/orders/order.schema.ts +0 -36
- package/src/modules/sale/orders/order.validator.ts +0 -44
- package/src/modules/sale/orders/validators/address.validator.ts +0 -50
- package/src/modules/sale/orders/validators/item.validator.ts +0 -14
- package/src/modules/sale/orders/validators/payment.validator.ts +0 -44
- package/src/modules/sale/orders/validators/shipping.validator.ts +0 -14
- package/src/modules/sale/payments/entities/status.entity.ts +0 -17
- package/src/modules/sale/payments/enums/billing.type.ts +0 -6
- package/src/modules/sale/payments/enums/payment.status.ts +0 -7
- package/src/modules/sale/payments/enums/shipping.type.ts +0 -4
- package/src/modules/sale/payments/payment.controller.ts +0 -45
- package/src/modules/sale/payments/payment.entity.ts +0 -25
- package/src/modules/sale/payments/payment.module.ts +0 -20
- package/src/modules/sale/payments/payment.repository.ts +0 -57
- package/src/modules/sale/payments/payment.schema.ts +0 -14
- package/src/modules/sale/payments/payment.validator.ts +0 -32
- package/src/modules/sale/sale.module.ts +0 -20
- package/src/services/auth0.service.ts +0 -49
- package/src/services/mongo.service.ts +0 -52
- package/test/auth/auth.spec.ts +0 -20
- package/test/main.ts +0 -12
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -21
- package/tsconfig.package.json +0 -22
|
@@ -1,65 +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 { GetUser } from '../../../decorators/user.decorator';
|
|
6
|
-
import { UserRepository } from '../../auth/users/user.repository';
|
|
7
|
-
import { OrderEntity } from './order.entity';
|
|
8
|
-
import { OrderRepository } from './order.repository';
|
|
9
|
-
import { CreateOrderValidator, UpdateOrderStatusValidator, UpdateOrderValidator } from './order.validator';
|
|
10
|
-
|
|
11
|
-
@Controller('/')
|
|
12
|
-
@ApiTags('sales')
|
|
13
|
-
export class OrderController extends AbstractController {
|
|
14
|
-
@Inject()
|
|
15
|
-
protected readonly $repository: OrderRepository;
|
|
16
|
-
|
|
17
|
-
@Inject()
|
|
18
|
-
protected readonly $userRepository: UserRepository;
|
|
19
|
-
|
|
20
|
-
@Get('/')
|
|
21
|
-
public find(@Query() validator: FindValidator<OrderEntity>) {
|
|
22
|
-
return this.$repository.find(validator);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@Post('/')
|
|
26
|
-
public async create(@Body() validator: CreateOrderValidator, @GetUser('sub') sub: string) {
|
|
27
|
-
// const user = await this.$userRepository.readByAuth0(sub)
|
|
28
|
-
const user = undefined;
|
|
29
|
-
|
|
30
|
-
return this.$repository.create(validator, user);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@Get('/me')
|
|
34
|
-
public async byCurrentUser(@Query() validator: FindValidator<OrderEntity>, @GetUser('sub') sub: string) {
|
|
35
|
-
const user = await this.$userRepository.readByAuth0(sub);
|
|
36
|
-
|
|
37
|
-
return this.$repository.findByUser(validator, user);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@Get('/:id')
|
|
41
|
-
public read(@Param() { id }: IdMongoValidator, @Query() validator?: ReadValidator) {
|
|
42
|
-
return this.$repository.read(id, validator);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@Patch('/:id')
|
|
46
|
-
public update(@Param('id') id: string, @Body() validator: UpdateOrderValidator) {
|
|
47
|
-
return this.$repository.update(id, validator);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
@Delete('/:id')
|
|
51
|
-
public delete(@Param() { id }: IdMongoValidator) {
|
|
52
|
-
return this.$repository.delete(id);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@Patch('/:id/status/:type')
|
|
56
|
-
public async updateStatus(
|
|
57
|
-
@Param() { id, type }: UpdateOrderStatusValidator,
|
|
58
|
-
@Body() validator: UpdateOrderValidator,
|
|
59
|
-
@GetUser('sub') sub: string,
|
|
60
|
-
) {
|
|
61
|
-
const user = await this.$userRepository.readByAuth0(sub);
|
|
62
|
-
|
|
63
|
-
return this.$repository.updateStatus(id, type, user);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Prop, Schema as Collection } from '@nestjs/mongoose';
|
|
2
|
-
import { Schema } from 'mongoose';
|
|
3
|
-
import type { MaybeEntity } from '../../../abstracts/abstract.entity';
|
|
4
|
-
import { $collection, AbstractEntity } from '../../../abstracts/abstract.entity';
|
|
5
|
-
import { UserEntity } from '../../auth/users/user.entity';
|
|
6
|
-
import { UserSchema } from '../../auth/users/user.schema';
|
|
7
|
-
import { CustomerEntity } from '../customers/customer.entity';
|
|
8
|
-
import { CustomerSchema } from '../customers/customer.schema';
|
|
9
|
-
import { PaymentEntity } from '../payments/payment.entity';
|
|
10
|
-
import { PaymentSchema } from '../payments/payment.schema';
|
|
11
|
-
import { AddressDocument } from './documents/address.document';
|
|
12
|
-
import { StatusDocument } from './documents/status.document';
|
|
13
|
-
import { ItemEntity, ItemSchema } from './entities/item.entity';
|
|
14
|
-
|
|
15
|
-
@Collection($collection)
|
|
16
|
-
export class OrderEntity extends AbstractEntity {
|
|
17
|
-
@Prop({ default: () => 1, type: Schema.Types.Number })
|
|
18
|
-
public number = 1;
|
|
19
|
-
|
|
20
|
-
@Prop({ default: () => [], type: [ItemSchema] })
|
|
21
|
-
public items: ItemEntity[] = [];
|
|
22
|
-
|
|
23
|
-
@Prop({ default: () => [], type: Schema.Types.Array })
|
|
24
|
-
public status: StatusDocument[] = [];
|
|
25
|
-
|
|
26
|
-
@Prop({ ref: PaymentSchema.name, required: true, type: Schema.Types.ObjectId })
|
|
27
|
-
public payment: MaybeEntity<PaymentEntity>;
|
|
28
|
-
|
|
29
|
-
@Prop({ ref: CustomerSchema.name, required: true, type: Schema.Types.ObjectId })
|
|
30
|
-
public customer: MaybeEntity<CustomerEntity>;
|
|
31
|
-
|
|
32
|
-
@Prop({ ref: UserSchema.name, required: true, type: Schema.Types.ObjectId })
|
|
33
|
-
public user: MaybeEntity<UserEntity>;
|
|
34
|
-
|
|
35
|
-
@Prop({ default: () => new AddressDocument(), required: true, type: Schema.Types.Mixed })
|
|
36
|
-
public address = new AddressDocument();
|
|
37
|
-
|
|
38
|
-
@Prop({ type: Schema.Types.String })
|
|
39
|
-
public description: string;
|
|
40
|
-
|
|
41
|
-
public readonly total: number;
|
|
42
|
-
|
|
43
|
-
public readonly fullNumber: string;
|
|
44
|
-
|
|
45
|
-
public readonly lastStatus: StatusDocument;
|
|
46
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Module, ModuleMetadata } from '@nestjs/common';
|
|
2
|
-
import { UserRepository } from '../../auth/users/user.repository';
|
|
3
|
-
import { ProductRepository } from '../../inventory/products/product.repository';
|
|
4
|
-
import { PaymentRepository } from '../payments/payment.repository';
|
|
5
|
-
import { OrderController } from './order.controller';
|
|
6
|
-
import { OrderRepository } from './order.repository';
|
|
7
|
-
|
|
8
|
-
export const metadata: ModuleMetadata = {
|
|
9
|
-
controllers: [OrderController],
|
|
10
|
-
exports: [OrderRepository],
|
|
11
|
-
imports: [],
|
|
12
|
-
providers: [OrderRepository, ProductRepository, PaymentRepository, UserRepository],
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
@Module(metadata)
|
|
16
|
-
export class OrderModule {
|
|
17
|
-
public static readonly path = '/orders';
|
|
18
|
-
|
|
19
|
-
public static readonly module = OrderModule;
|
|
20
|
-
|
|
21
|
-
public static readonly children = metadata.imports;
|
|
22
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { Inject, Injectable, Logger, OnModuleInit } from '@nestjs/common';
|
|
2
|
-
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
-
import { Model } from 'mongoose';
|
|
4
|
-
import { AbstractRepository } from '../../../abstracts/abstarct.repository';
|
|
5
|
-
import { FindValidator } from '../../../abstracts/abstract.validator';
|
|
6
|
-
import { UserEntity } from '../../auth/users/user.entity';
|
|
7
|
-
import { UserRepository } from '../../auth/users/user.repository';
|
|
8
|
-
import { ProductRepository } from '../../inventory/products/product.repository';
|
|
9
|
-
import { PaymentRepository } from '../payments/payment.repository';
|
|
10
|
-
import { CreatePaymentValidator } from '../payments/payment.validator';
|
|
11
|
-
import { StatusDocument } from './documents/status.document';
|
|
12
|
-
import { ItemEntity } from './entities/item.entity';
|
|
13
|
-
import { OrderStatus } from './enums/order.status';
|
|
14
|
-
import { OrderEntity } from './order.entity';
|
|
15
|
-
import { OrderSchema } from './order.schema';
|
|
16
|
-
import { CreateOrderValidator, UpdateOrderValidator } from './order.validator';
|
|
17
|
-
|
|
18
|
-
export let autoIncrement = 1;
|
|
19
|
-
|
|
20
|
-
@Injectable()
|
|
21
|
-
export class OrderRepository extends AbstractRepository<OrderEntity> implements OnModuleInit {
|
|
22
|
-
@InjectModel(OrderSchema.name)
|
|
23
|
-
protected readonly $model: Model<OrderEntity>;
|
|
24
|
-
|
|
25
|
-
@Inject()
|
|
26
|
-
protected readonly $products: ProductRepository;
|
|
27
|
-
|
|
28
|
-
@Inject()
|
|
29
|
-
protected readonly $payments: PaymentRepository;
|
|
30
|
-
|
|
31
|
-
@Inject()
|
|
32
|
-
protected readonly $users: UserRepository;
|
|
33
|
-
|
|
34
|
-
public async onModuleInit() {
|
|
35
|
-
const lastOne = await this.$model.findOne<OrderEntity>(undefined, undefined, {
|
|
36
|
-
sort: { number: 'descending' },
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
if (!lastOne) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return (autoIncrement = lastOne.number);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public findByUser(validator: FindValidator<OrderEntity>, user: UserEntity) {
|
|
47
|
-
validator.filters.user = user._id;
|
|
48
|
-
|
|
49
|
-
return super.find(validator);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public async create(validator: CreateOrderValidator, user?: UserEntity) {
|
|
53
|
-
const order = new this.$model();
|
|
54
|
-
|
|
55
|
-
order.number = ++autoIncrement;
|
|
56
|
-
order.user = user;
|
|
57
|
-
order.address = validator.shipping.address;
|
|
58
|
-
order.description = validator.description;
|
|
59
|
-
|
|
60
|
-
const status = new StatusDocument();
|
|
61
|
-
status.date = new Date();
|
|
62
|
-
status.name = OrderStatus.CREATED;
|
|
63
|
-
status.user = order.user._id as any;
|
|
64
|
-
|
|
65
|
-
order.status.push(status);
|
|
66
|
-
|
|
67
|
-
for await (const itemValidator of validator.items) {
|
|
68
|
-
const item = new ItemEntity();
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
const product = await this.$products.read(itemValidator.product);
|
|
72
|
-
|
|
73
|
-
item.description = itemValidator.description;
|
|
74
|
-
item.quantity = itemValidator.quantity;
|
|
75
|
-
item.product = product._id as any;
|
|
76
|
-
item.price = product.price;
|
|
77
|
-
} catch (reason: unknown) {
|
|
78
|
-
Logger.warn(`When creating order occurs: [${reason}] `);
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
order.items.push(item);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const payment = new CreatePaymentValidator();
|
|
86
|
-
|
|
87
|
-
payment.order = order._id;
|
|
88
|
-
payment.total = order.total;
|
|
89
|
-
payment.type = validator.billing.type;
|
|
90
|
-
payment.user = user._id;
|
|
91
|
-
payment.payload = validator.billing.payload;
|
|
92
|
-
|
|
93
|
-
order.payment = await this.$payments.create(payment, order);
|
|
94
|
-
|
|
95
|
-
await order.save();
|
|
96
|
-
|
|
97
|
-
return order;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public async update(id: string, validator: UpdateOrderValidator) {
|
|
101
|
-
const order = await this.read(id);
|
|
102
|
-
|
|
103
|
-
await order.save();
|
|
104
|
-
|
|
105
|
-
return order;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
public async updateStatus(id: string, type: OrderStatus, user: UserEntity) {
|
|
109
|
-
const order = await this.read(id);
|
|
110
|
-
|
|
111
|
-
const status = new StatusDocument();
|
|
112
|
-
status.date = new Date();
|
|
113
|
-
status.name = type;
|
|
114
|
-
status.user = user;
|
|
115
|
-
|
|
116
|
-
order.status.push(status);
|
|
117
|
-
|
|
118
|
-
await order.save();
|
|
119
|
-
|
|
120
|
-
return order;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { SchemaFactory } from '@nestjs/mongoose';
|
|
2
|
-
import { OrderEntity } from './order.entity';
|
|
3
|
-
|
|
4
|
-
export namespace OrderSchema {
|
|
5
|
-
export const name = 'sale_orders';
|
|
6
|
-
|
|
7
|
-
export const schema = SchemaFactory.createForClass(OrderEntity);
|
|
8
|
-
|
|
9
|
-
schema.virtual('total').get(function () {
|
|
10
|
-
return this.items.reduce((amount, current) => {
|
|
11
|
-
const price = current.price || 0;
|
|
12
|
-
const quantity = current.quantity || 1;
|
|
13
|
-
|
|
14
|
-
return amount + price * quantity;
|
|
15
|
-
}, 0);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
schema.virtual('fullNumber').get(function () {
|
|
19
|
-
const createdAt = new Date(this.createdAt);
|
|
20
|
-
|
|
21
|
-
const year = `Y${createdAt.getFullYear().toString().slice(2)}`;
|
|
22
|
-
const month = `M${(createdAt.getMonth() + 1).toString().padStart(2, '0')}`;
|
|
23
|
-
const day = `D${createdAt.getDate().toString().padStart(2, '0')}`;
|
|
24
|
-
|
|
25
|
-
const date = `${year}${month}${day}`;
|
|
26
|
-
const number = this.number.toString().padStart(4, '0');
|
|
27
|
-
|
|
28
|
-
return `${date}-${number}`.toUpperCase();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
schema.virtual('lastStatus').get(function () {
|
|
32
|
-
const [first] = this.status.reverse();
|
|
33
|
-
|
|
34
|
-
return first;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Type } from 'class-transformer';
|
|
2
|
-
import {
|
|
3
|
-
ArrayNotEmpty,
|
|
4
|
-
IsArray,
|
|
5
|
-
IsEnum,
|
|
6
|
-
IsNotEmptyObject,
|
|
7
|
-
IsOptional,
|
|
8
|
-
IsString,
|
|
9
|
-
ValidateNested,
|
|
10
|
-
} from 'class-validator';
|
|
11
|
-
import { IdMongoValidator } from '../../../abstracts/abstract.validator';
|
|
12
|
-
import { OrderStatus } from './enums/order.status';
|
|
13
|
-
import { BillingValidator } from './validators/billing.validator';
|
|
14
|
-
import { CreateItemValidator } from './validators/item.validator';
|
|
15
|
-
import { ShippingValidator } from './validators/shipping.validator';
|
|
16
|
-
|
|
17
|
-
export class CreateOrderValidator {
|
|
18
|
-
@IsArray()
|
|
19
|
-
@ArrayNotEmpty()
|
|
20
|
-
@Type(() => CreateItemValidator)
|
|
21
|
-
@ValidateNested()
|
|
22
|
-
public items: CreateItemValidator[] = [];
|
|
23
|
-
|
|
24
|
-
@Type(() => BillingValidator)
|
|
25
|
-
@ValidateNested()
|
|
26
|
-
@IsNotEmptyObject()
|
|
27
|
-
public billing = new BillingValidator();
|
|
28
|
-
|
|
29
|
-
@Type(() => ShippingValidator)
|
|
30
|
-
@ValidateNested()
|
|
31
|
-
@IsNotEmptyObject()
|
|
32
|
-
public shipping = new ShippingValidator();
|
|
33
|
-
|
|
34
|
-
@IsString()
|
|
35
|
-
@IsOptional()
|
|
36
|
-
public description = String();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export class UpdateOrderValidator extends CreateOrderValidator {}
|
|
40
|
-
|
|
41
|
-
export class UpdateOrderStatusValidator extends IdMongoValidator {
|
|
42
|
-
@IsEnum(OrderStatus)
|
|
43
|
-
public type: OrderStatus;
|
|
44
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { IsISO31661Alpha2, IsOptional, IsString, Matches } from 'class-validator';
|
|
2
|
-
|
|
3
|
-
export class CreateAddressValidator {
|
|
4
|
-
@IsString()
|
|
5
|
-
public street: string;
|
|
6
|
-
|
|
7
|
-
@IsString()
|
|
8
|
-
@IsOptional()
|
|
9
|
-
public complement: string;
|
|
10
|
-
|
|
11
|
-
@IsString()
|
|
12
|
-
public city: string;
|
|
13
|
-
|
|
14
|
-
@IsString()
|
|
15
|
-
public state: string;
|
|
16
|
-
|
|
17
|
-
@IsString()
|
|
18
|
-
public number: string;
|
|
19
|
-
|
|
20
|
-
@IsString()
|
|
21
|
-
@IsOptional()
|
|
22
|
-
public neighborhood: string;
|
|
23
|
-
|
|
24
|
-
@IsString()
|
|
25
|
-
@Matches(/[a-zA-Z0-9_-]{8}/, { message: 'zipCode must be valid' })
|
|
26
|
-
public zipCode: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export class AddressValidator {
|
|
30
|
-
@IsString()
|
|
31
|
-
public line1: string;
|
|
32
|
-
|
|
33
|
-
@IsString()
|
|
34
|
-
@IsOptional()
|
|
35
|
-
public line2: string;
|
|
36
|
-
|
|
37
|
-
@IsString()
|
|
38
|
-
public city: string;
|
|
39
|
-
|
|
40
|
-
@IsString()
|
|
41
|
-
public state: string;
|
|
42
|
-
|
|
43
|
-
@IsString()
|
|
44
|
-
@IsISO31661Alpha2()
|
|
45
|
-
public country: string;
|
|
46
|
-
|
|
47
|
-
@IsString()
|
|
48
|
-
@Matches(/[a-zA-Z0-9_-]{8}/, { message: 'zipCode must be valid' })
|
|
49
|
-
public code: string;
|
|
50
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { IsInt, IsMongoId, IsOptional, IsPositive, IsString } from 'class-validator';
|
|
2
|
-
|
|
3
|
-
export class CreateItemValidator {
|
|
4
|
-
@IsMongoId()
|
|
5
|
-
public product: string;
|
|
6
|
-
|
|
7
|
-
@IsPositive()
|
|
8
|
-
@IsInt()
|
|
9
|
-
public quantity: number;
|
|
10
|
-
|
|
11
|
-
@IsString()
|
|
12
|
-
@IsOptional()
|
|
13
|
-
public description?: string;
|
|
14
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Type } from 'class-transformer';
|
|
2
|
-
import {
|
|
3
|
-
IsNotEmpty,
|
|
4
|
-
IsNumberString,
|
|
5
|
-
IsOptional,
|
|
6
|
-
IsPositive,
|
|
7
|
-
IsString,
|
|
8
|
-
Length,
|
|
9
|
-
Max,
|
|
10
|
-
Min,
|
|
11
|
-
ValidateNested,
|
|
12
|
-
} from 'class-validator';
|
|
13
|
-
|
|
14
|
-
export class PaymentCardValidator {
|
|
15
|
-
@IsString()
|
|
16
|
-
@IsNotEmpty()
|
|
17
|
-
public number = String();
|
|
18
|
-
|
|
19
|
-
@IsString()
|
|
20
|
-
@IsNotEmpty()
|
|
21
|
-
public name = String();
|
|
22
|
-
|
|
23
|
-
@IsPositive()
|
|
24
|
-
@Min(1)
|
|
25
|
-
@Max(12)
|
|
26
|
-
public expMonth: number;
|
|
27
|
-
|
|
28
|
-
@IsPositive()
|
|
29
|
-
@Min(new Date().getFullYear())
|
|
30
|
-
@IsNotEmpty()
|
|
31
|
-
public expYear: number;
|
|
32
|
-
|
|
33
|
-
@IsNumberString()
|
|
34
|
-
@Length(3, 4)
|
|
35
|
-
@IsNotEmpty()
|
|
36
|
-
public cvv = String();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export class PaymentValidator {
|
|
40
|
-
@ValidateNested()
|
|
41
|
-
@Type(() => PaymentCardValidator)
|
|
42
|
-
@IsOptional()
|
|
43
|
-
public card = new PaymentCardValidator();
|
|
44
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ShippingType } from '../../payments/enums/shipping.type';
|
|
2
|
-
import { AddressValidator } from './address.validator';
|
|
3
|
-
|
|
4
|
-
export class ShippingValidator {
|
|
5
|
-
public address = new AddressValidator();
|
|
6
|
-
|
|
7
|
-
public type: ShippingType;
|
|
8
|
-
|
|
9
|
-
public name = String();
|
|
10
|
-
|
|
11
|
-
public phone = String();
|
|
12
|
-
|
|
13
|
-
public email = String();
|
|
14
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Prop } from '@nestjs/mongoose';
|
|
2
|
-
import { Schema } from 'mongoose';
|
|
3
|
-
import type { MaybeEntity } from '../../../../abstracts/abstract.entity';
|
|
4
|
-
import { UserEntity } from '../../../auth/users/user.entity';
|
|
5
|
-
import { UserSchema } from '../../../auth/users/user.schema';
|
|
6
|
-
import { PaymentStatus } from '../enums/payment.status';
|
|
7
|
-
|
|
8
|
-
export class StatusEntity {
|
|
9
|
-
@Prop({ enum: PaymentStatus, required: true, type: Schema.Types.String })
|
|
10
|
-
public name: PaymentStatus;
|
|
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: Date;
|
|
17
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Body, Controller, Delete, Get, Inject, Param, Patch, 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 { GetUser } from '../../../decorators/user.decorator';
|
|
6
|
-
import { UserRepository } from '../../auth/users/user.repository';
|
|
7
|
-
import { PaymentEntity } from './payment.entity';
|
|
8
|
-
import { PaymentRepository } from './payment.repository';
|
|
9
|
-
import { UpdatePaymentStatusValidator, UpdatePaymentValidator } from './payment.validator';
|
|
10
|
-
|
|
11
|
-
@Controller('/')
|
|
12
|
-
@ApiTags('sales')
|
|
13
|
-
export class PaymentController extends AbstractController {
|
|
14
|
-
@Inject()
|
|
15
|
-
protected readonly $repository: PaymentRepository;
|
|
16
|
-
|
|
17
|
-
@Inject()
|
|
18
|
-
protected readonly $userRepository: UserRepository;
|
|
19
|
-
|
|
20
|
-
@Get('/')
|
|
21
|
-
public find(@Query() validator: FindValidator<PaymentEntity>) {
|
|
22
|
-
return this.$repository.find(validator);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@Get('/:id')
|
|
26
|
-
public read(@Param() { id }: IdMongoValidator, @Query() validator?: ReadValidator) {
|
|
27
|
-
return this.$repository.read(id, validator);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@Delete('/:id')
|
|
31
|
-
public delete(@Param() { id }: IdMongoValidator) {
|
|
32
|
-
return this.$repository.delete(id);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@Patch('/:id/status/:type')
|
|
36
|
-
public async updateStatus(
|
|
37
|
-
@Param() { id, type }: UpdatePaymentStatusValidator,
|
|
38
|
-
@Body() validator: UpdatePaymentValidator,
|
|
39
|
-
@GetUser('sub') sub: string,
|
|
40
|
-
) {
|
|
41
|
-
const user = await this.$userRepository.readByAuth0(sub);
|
|
42
|
-
|
|
43
|
-
return this.$repository.updateStatus(id, type, user);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,25 +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 { OrderEntity } from '../orders/order.entity';
|
|
5
|
-
import { StatusEntity } from './entities/status.entity';
|
|
6
|
-
import { BillingType } from './enums/billing.type';
|
|
7
|
-
|
|
8
|
-
@Collection($collection)
|
|
9
|
-
export class PaymentEntity extends AbstractEntity {
|
|
10
|
-
@Prop({ default: () => [], type: Schema.Types.Array })
|
|
11
|
-
public status: StatusEntity[] = [];
|
|
12
|
-
|
|
13
|
-
@Prop({ required: true, type: Schema.Types.Number })
|
|
14
|
-
public total: number;
|
|
15
|
-
|
|
16
|
-
@Prop({ default: () => 0, type: Schema.Types.Number })
|
|
17
|
-
public fee = 0;
|
|
18
|
-
|
|
19
|
-
@Prop({ enum: BillingType, required: true, type: Schema.Types.String })
|
|
20
|
-
public type: BillingType;
|
|
21
|
-
|
|
22
|
-
public readonly order: OrderEntity;
|
|
23
|
-
|
|
24
|
-
public readonly lastStatus: StatusEntity;
|
|
25
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Module, ModuleMetadata } from '@nestjs/common';
|
|
2
|
-
import { UserRepository } from '../../auth/users/user.repository';
|
|
3
|
-
import { PaymentController } from './payment.controller';
|
|
4
|
-
import { PaymentRepository } from './payment.repository';
|
|
5
|
-
|
|
6
|
-
export const metadata: ModuleMetadata = {
|
|
7
|
-
controllers: [PaymentController],
|
|
8
|
-
exports: [PaymentRepository],
|
|
9
|
-
imports: [],
|
|
10
|
-
providers: [PaymentRepository, UserRepository],
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
@Module(metadata)
|
|
14
|
-
export class PaymentModule {
|
|
15
|
-
public static readonly path = '/payments';
|
|
16
|
-
|
|
17
|
-
public static readonly module = PaymentModule;
|
|
18
|
-
|
|
19
|
-
public static readonly children = metadata.imports;
|
|
20
|
-
}
|
|
@@ -1,57 +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 { UserEntity } from '../../auth/users/user.entity';
|
|
6
|
-
import { OrderEntity } from '../orders/order.entity';
|
|
7
|
-
import { StatusEntity } from './entities/status.entity';
|
|
8
|
-
import { PaymentStatus } from './enums/payment.status';
|
|
9
|
-
import { PaymentEntity } from './payment.entity';
|
|
10
|
-
import { PaymentSchema } from './payment.schema';
|
|
11
|
-
import { CreatePaymentValidator, UpdatePaymentValidator } from './payment.validator';
|
|
12
|
-
|
|
13
|
-
@Injectable()
|
|
14
|
-
export class PaymentRepository extends AbstractRepository<PaymentEntity> {
|
|
15
|
-
@InjectModel(PaymentSchema.name)
|
|
16
|
-
protected readonly $model: Model<PaymentEntity>;
|
|
17
|
-
|
|
18
|
-
public async create(validator: CreatePaymentValidator, order: OrderEntity) {
|
|
19
|
-
const payment = new this.$model();
|
|
20
|
-
|
|
21
|
-
const status = new StatusEntity();
|
|
22
|
-
status.date = new Date();
|
|
23
|
-
status.name = PaymentStatus.UNPAID;
|
|
24
|
-
status.user = validator.user as any;
|
|
25
|
-
payment.status.push(status);
|
|
26
|
-
|
|
27
|
-
payment.type = validator.type;
|
|
28
|
-
payment.total = order.total;
|
|
29
|
-
|
|
30
|
-
await payment.save();
|
|
31
|
-
|
|
32
|
-
return payment;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public async update(id: string, validator: UpdatePaymentValidator) {
|
|
36
|
-
const payment = await this.read(id);
|
|
37
|
-
|
|
38
|
-
await payment.save();
|
|
39
|
-
|
|
40
|
-
return payment;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public async updateStatus(id: string, type: PaymentStatus, user: UserEntity) {
|
|
44
|
-
const payment = await this.read(id);
|
|
45
|
-
|
|
46
|
-
const status = new StatusEntity();
|
|
47
|
-
status.date = new Date();
|
|
48
|
-
status.name = type;
|
|
49
|
-
status.user = user;
|
|
50
|
-
|
|
51
|
-
payment.status.push(status);
|
|
52
|
-
|
|
53
|
-
await payment.save();
|
|
54
|
-
|
|
55
|
-
return payment;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { SchemaFactory } from '@nestjs/mongoose';
|
|
2
|
-
import { PaymentEntity } from './payment.entity';
|
|
3
|
-
|
|
4
|
-
export namespace PaymentSchema {
|
|
5
|
-
export const name = 'sales_payments';
|
|
6
|
-
|
|
7
|
-
export const schema = SchemaFactory.createForClass(PaymentEntity);
|
|
8
|
-
|
|
9
|
-
schema.virtual('lastStatus').get(function () {
|
|
10
|
-
const [first] = this.status.reverse();
|
|
11
|
-
|
|
12
|
-
return first;
|
|
13
|
-
});
|
|
14
|
-
}
|