@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,30 +0,0 @@
|
|
|
1
|
-
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
|
2
|
-
import { Request } from 'express';
|
|
3
|
-
|
|
4
|
-
export interface DecodedUser {
|
|
5
|
-
iss: string;
|
|
6
|
-
sub: string;
|
|
7
|
-
aud: string[];
|
|
8
|
-
iat: number;
|
|
9
|
-
exp: number;
|
|
10
|
-
azp: string;
|
|
11
|
-
scope: string;
|
|
12
|
-
org_id?: string;
|
|
13
|
-
given_name: string;
|
|
14
|
-
family_name: string;
|
|
15
|
-
nickname?: string;
|
|
16
|
-
name: string;
|
|
17
|
-
picture: string;
|
|
18
|
-
locale: 'es';
|
|
19
|
-
updated_at: Date;
|
|
20
|
-
email: string;
|
|
21
|
-
email_verified: boolean;
|
|
22
|
-
sid: string;
|
|
23
|
-
nonce: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const GetUser = createParamDecorator((key: keyof DecodedUser, ctx: ExecutionContext) => {
|
|
27
|
-
const { user } = ctx.switchToHttp().getRequest<Request>();
|
|
28
|
-
|
|
29
|
-
return key ? user?.[key] : user;
|
|
30
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { PreconditionFailedException } from '@nestjs/common';
|
|
2
|
-
|
|
3
|
-
export class MissingIdentityException extends PreconditionFailedException {
|
|
4
|
-
public constructor() {
|
|
5
|
-
super('Missing identity parameter on your request');
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
public static throw() {
|
|
9
|
-
throw new MissingIdentityException();
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
|
|
2
|
-
import { InjectConnection, InjectModel } from '@nestjs/mongoose';
|
|
3
|
-
import { Connection, Model } from 'mongoose';
|
|
4
|
-
import { finalize } from 'rxjs/operators';
|
|
5
|
-
import { FileEntity } from '../modules/asset/files/file.entity';
|
|
6
|
-
import { FileSchema } from '../modules/asset/files/file.schema';
|
|
7
|
-
import { OrganizationEntity } from '../modules/auth/organizations/organization.entity';
|
|
8
|
-
import { OrganizationSchema } from '../modules/auth/organizations/organization.schema';
|
|
9
|
-
import { UserEntity } from '../modules/auth/users/user.entity';
|
|
10
|
-
import { BrandEntity } from '../modules/inventory/brands/brand.entity';
|
|
11
|
-
import { BrandSchema } from '../modules/inventory/brands/brand.schema';
|
|
12
|
-
import { CategoryEntity } from '../modules/inventory/categories/category.entity';
|
|
13
|
-
import { CategorySchema } from '../modules/inventory/categories/category.schema';
|
|
14
|
-
import { ComplementEntity } from '../modules/inventory/complements/complement.entity';
|
|
15
|
-
import { ComplementSchema } from '../modules/inventory/complements/complement.schema';
|
|
16
|
-
import { ProductEntity } from '../modules/inventory/products/product.entity';
|
|
17
|
-
import { ProductSchema } from '../modules/inventory/products/product.schema';
|
|
18
|
-
import { CustomerEntity } from '../modules/sale/customers/customer.entity';
|
|
19
|
-
import { CustomerSchema } from '../modules/sale/customers/customer.schema';
|
|
20
|
-
import { OrderEntity } from '../modules/sale/orders/order.entity';
|
|
21
|
-
import { OrderSchema } from '../modules/sale/orders/order.schema';
|
|
22
|
-
import { PaymentEntity } from '../modules/sale/payments/payment.entity';
|
|
23
|
-
import { PaymentSchema } from '../modules/sale/payments/payment.schema';
|
|
24
|
-
|
|
25
|
-
@Injectable()
|
|
26
|
-
export class MongoInterceptor implements NestInterceptor {
|
|
27
|
-
@InjectConnection()
|
|
28
|
-
protected readonly $connection: Connection;
|
|
29
|
-
|
|
30
|
-
@InjectModel(OrganizationSchema.name)
|
|
31
|
-
protected readonly authOrganization: Model<OrganizationEntity>;
|
|
32
|
-
|
|
33
|
-
@InjectModel(OrganizationSchema.name)
|
|
34
|
-
protected readonly authUser: Model<UserEntity>;
|
|
35
|
-
|
|
36
|
-
@InjectModel(CategorySchema.name)
|
|
37
|
-
protected readonly inventoryCategory: Model<CategoryEntity>;
|
|
38
|
-
|
|
39
|
-
@InjectModel(FileSchema.name)
|
|
40
|
-
protected readonly assetFile: Model<FileEntity>;
|
|
41
|
-
|
|
42
|
-
@InjectModel(BrandSchema.name)
|
|
43
|
-
protected readonly inventoryBrand: Model<BrandEntity>;
|
|
44
|
-
|
|
45
|
-
@InjectModel(ProductSchema.name)
|
|
46
|
-
protected readonly inventoryProduct: Model<ProductEntity>;
|
|
47
|
-
|
|
48
|
-
@InjectModel(ComplementSchema.name)
|
|
49
|
-
protected readonly inventoryComplement: Model<ComplementEntity>;
|
|
50
|
-
|
|
51
|
-
@InjectModel(OrderSchema.name)
|
|
52
|
-
protected readonly saleOrder: Model<OrderEntity>;
|
|
53
|
-
|
|
54
|
-
@InjectModel(CustomerSchema.name)
|
|
55
|
-
protected readonly saleCustomer: Model<CustomerEntity>;
|
|
56
|
-
|
|
57
|
-
@InjectModel(PaymentSchema.name)
|
|
58
|
-
protected readonly salePayment: Model<PaymentEntity>;
|
|
59
|
-
|
|
60
|
-
public intercept(context: ExecutionContext, next: CallHandler) {
|
|
61
|
-
return next.handle().pipe(finalize(() => this.$connection.close()));
|
|
62
|
-
}
|
|
63
|
-
}
|
package/src/main.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@nestjs/common';
|
|
2
|
-
import { HttpsOptions } from '@nestjs/common/interfaces/external/https-options.interface';
|
|
3
|
-
import { NestApplication, NestFactory } from '@nestjs/core';
|
|
4
|
-
// import { readFileSync } from 'fs';
|
|
5
|
-
import { createNestApp } from '../app';
|
|
6
|
-
import { AppConfig } from './app.config';
|
|
7
|
-
import { AppModule } from './app.module';
|
|
8
|
-
|
|
9
|
-
(async () => {
|
|
10
|
-
const httpsOptions: HttpsOptions = undefined;
|
|
11
|
-
|
|
12
|
-
// if (AppConfig.SERVER.isDEV) {
|
|
13
|
-
// httpsOptions = {
|
|
14
|
-
// key: readFileSync('./.cert/key.pem'),
|
|
15
|
-
// cert: readFileSync('./.cert/cert.pem'),
|
|
16
|
-
// };
|
|
17
|
-
// }
|
|
18
|
-
|
|
19
|
-
const app = await NestFactory.create(AppModule, {
|
|
20
|
-
cors: true,
|
|
21
|
-
httpsOptions,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
return createNestApp(app)
|
|
25
|
-
.listen(AppConfig.SERVER.port)
|
|
26
|
-
.then(async () => Logger.verbose(`Running on: ${await app.getUrl()}`, NestApplication.name));
|
|
27
|
-
})();
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Injectable, Logger, NestMiddleware } from '@nestjs/common';
|
|
2
|
-
import { NextFunction, Request, Response } from 'express';
|
|
3
|
-
import { MongoService } from '../services/mongo.service';
|
|
4
|
-
|
|
5
|
-
@Injectable()
|
|
6
|
-
export class RouterMiddleware implements NestMiddleware {
|
|
7
|
-
public use(req: Request, res: Response, next: NextFunction) {
|
|
8
|
-
const identity = MongoService.extractIdentityFromRequest(req);
|
|
9
|
-
|
|
10
|
-
Logger.debug(`[${req.method}]: ${req.originalUrl}`, identity);
|
|
11
|
-
|
|
12
|
-
return next();
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Module, ModuleMetadata } from '@nestjs/common';
|
|
2
|
-
import { AbstractRouter } from '../../abstracts/abstract.router';
|
|
3
|
-
import { FileModule } from './files/file.module';
|
|
4
|
-
|
|
5
|
-
export const metadata: ModuleMetadata = {
|
|
6
|
-
controllers: [],
|
|
7
|
-
exports: [FileModule],
|
|
8
|
-
imports: [FileModule],
|
|
9
|
-
providers: [],
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
@Module(metadata)
|
|
13
|
-
export class AssetModule extends AbstractRouter {
|
|
14
|
-
public static readonly path = '/asset';
|
|
15
|
-
|
|
16
|
-
public static readonly module = AssetModule;
|
|
17
|
-
|
|
18
|
-
public static readonly children = metadata.imports;
|
|
19
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Controller, Delete, Inject, Param, Post, UploadedFiles, UseInterceptors } from '@nestjs/common';
|
|
2
|
-
import { AnyFilesInterceptor } from '@nestjs/platform-express';
|
|
3
|
-
import { ApiTags } from '@nestjs/swagger';
|
|
4
|
-
import { FileRepository } from './file.repository';
|
|
5
|
-
|
|
6
|
-
@Controller()
|
|
7
|
-
@ApiTags('asset')
|
|
8
|
-
export class FileController {
|
|
9
|
-
@Inject()
|
|
10
|
-
protected readonly $repository: FileRepository;
|
|
11
|
-
|
|
12
|
-
@Post('/')
|
|
13
|
-
@UseInterceptors(AnyFilesInterceptor())
|
|
14
|
-
public async files(@UploadedFiles() images: Express.Multer.File[] = []) {
|
|
15
|
-
return this.$repository.upload(images);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@Delete('/:id')
|
|
19
|
-
public delete(@Param('id') id: string) {
|
|
20
|
-
return this.$repository.delete(id);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Prop, Schema } from '@nestjs/mongoose';
|
|
2
|
-
import { Schema as MongoSchema } from 'mongoose';
|
|
3
|
-
import { AbstractEntity } from '../../../abstracts/abstract.entity';
|
|
4
|
-
|
|
5
|
-
@Schema({ timestamps: true })
|
|
6
|
-
export class FileEntity extends AbstractEntity {
|
|
7
|
-
@Prop({ type: MongoSchema.Types.String, required: true, unique: true })
|
|
8
|
-
public name: string;
|
|
9
|
-
|
|
10
|
-
@Prop({ type: MongoSchema.Types.String, required: true })
|
|
11
|
-
public url: string;
|
|
12
|
-
|
|
13
|
-
@Prop({ type: MongoSchema.Types.Boolean, default: true })
|
|
14
|
-
public weak = true;
|
|
15
|
-
|
|
16
|
-
@Prop({ type: MongoSchema.Types.String, nullable: true })
|
|
17
|
-
public description: string;
|
|
18
|
-
|
|
19
|
-
@Prop({ type: MongoSchema.Types.String })
|
|
20
|
-
public type: string;
|
|
21
|
-
|
|
22
|
-
@Prop({ type: MongoSchema.Types.Number, required: true, default: 0 })
|
|
23
|
-
public size = 0;
|
|
24
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Module, ModuleMetadata } from '@nestjs/common';
|
|
2
|
-
import { AbstractRouter } from '../../../abstracts/abstract.router';
|
|
3
|
-
import { FileController } from './file.controller';
|
|
4
|
-
import { FileRepository } from './file.repository';
|
|
5
|
-
import { FileService } from './file.service';
|
|
6
|
-
|
|
7
|
-
export const metadata: ModuleMetadata = {
|
|
8
|
-
imports: [],
|
|
9
|
-
controllers: [FileController],
|
|
10
|
-
providers: [FileRepository, FileService],
|
|
11
|
-
exports: [FileRepository],
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
@Module(metadata)
|
|
15
|
-
export class FileModule extends AbstractRouter {
|
|
16
|
-
public static readonly path = '/files';
|
|
17
|
-
|
|
18
|
-
public static readonly module = FileModule;
|
|
19
|
-
|
|
20
|
-
public static readonly children = metadata.imports;
|
|
21
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
-
import { writeFileSync } from 'fs';
|
|
4
|
-
import { Model } from 'mongoose';
|
|
5
|
-
import { AbstractRepository } from '../../../abstracts/abstarct.repository';
|
|
6
|
-
import { FileEntity } from './file.entity';
|
|
7
|
-
import { FileSchema } from './file.schema';
|
|
8
|
-
|
|
9
|
-
@Injectable()
|
|
10
|
-
export class FileRepository extends AbstractRepository<FileEntity> {
|
|
11
|
-
@InjectModel(FileSchema.name)
|
|
12
|
-
public readonly $model: Model<FileEntity>;
|
|
13
|
-
|
|
14
|
-
public async upload(files: Express.Multer.File[] = []) {
|
|
15
|
-
const assets: FileEntity[] = [];
|
|
16
|
-
|
|
17
|
-
for (const file of files) {
|
|
18
|
-
const asset: FileEntity = new this.$model();
|
|
19
|
-
|
|
20
|
-
const ext = file.originalname.split('.').pop();
|
|
21
|
-
const name = `${asset._id}.${ext}`;
|
|
22
|
-
const filePath = `uploads/${name}`;
|
|
23
|
-
|
|
24
|
-
asset.url = filePath;
|
|
25
|
-
asset.name = name;
|
|
26
|
-
asset.size = file.size;
|
|
27
|
-
asset.type = file.mimetype;
|
|
28
|
-
|
|
29
|
-
assets.push(await this.$model.create(asset));
|
|
30
|
-
|
|
31
|
-
writeFileSync(filePath, file.buffer);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return Promise.all(assets);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public create(partial: Partial<FileEntity>): Promise<FileEntity> {
|
|
38
|
-
return this.$model.create(partial);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public update(id: string, params: unknown): Promise<FileEntity> {
|
|
42
|
-
return Promise.resolve(undefined);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Controller, Get, Inject, NotAcceptableException, NotFoundException, Put, Req } from '@nestjs/common';
|
|
2
|
-
import { ApiTags } from '@nestjs/swagger';
|
|
3
|
-
import type { Request } from 'express';
|
|
4
|
-
import { Public } from '../../decorators/public.decorator';
|
|
5
|
-
import { DecodedUser, GetUser } from '../../decorators/user.decorator';
|
|
6
|
-
import { OrganizationRepository } from './organizations/organization.repository';
|
|
7
|
-
import { UserRepository } from './users/user.repository';
|
|
8
|
-
|
|
9
|
-
@Controller('/')
|
|
10
|
-
@ApiTags('auth')
|
|
11
|
-
export class AuthController {
|
|
12
|
-
@Inject()
|
|
13
|
-
protected readonly $user: UserRepository;
|
|
14
|
-
|
|
15
|
-
@Inject()
|
|
16
|
-
protected readonly $organization: OrganizationRepository;
|
|
17
|
-
|
|
18
|
-
@Put('/token')
|
|
19
|
-
public token(@GetUser() user: DecodedUser) {
|
|
20
|
-
return this.$user.upsert(user);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@Get('/resolve')
|
|
24
|
-
@Public()
|
|
25
|
-
public async resolve(@Req() req: Request) {
|
|
26
|
-
const list = await this.$organization.find();
|
|
27
|
-
const { origin, identity } = req.headers;
|
|
28
|
-
|
|
29
|
-
if (identity) {
|
|
30
|
-
return this.$organization.read(String(identity));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!origin) {
|
|
34
|
-
throw new NotAcceptableException();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const { hostname } = new URL(origin);
|
|
38
|
-
|
|
39
|
-
const result = list.find((item) => {
|
|
40
|
-
const domain = item.metadata?.domain;
|
|
41
|
-
|
|
42
|
-
if (!domain) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const { name } = domain;
|
|
47
|
-
|
|
48
|
-
return String(name).includes(hostname);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
if (!result) {
|
|
52
|
-
throw new NotFoundException('Store Not Found');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Module, type ModuleMetadata } from '@nestjs/common';
|
|
2
|
-
import { AuthController } from './auth.controller';
|
|
3
|
-
import { OrganizationModule } from './organizations/organization.module';
|
|
4
|
-
import { UserModule } from './users/user.module';
|
|
5
|
-
|
|
6
|
-
const metadata: ModuleMetadata = {
|
|
7
|
-
controllers: [AuthController],
|
|
8
|
-
exports: [UserModule],
|
|
9
|
-
imports: [UserModule, OrganizationModule],
|
|
10
|
-
providers: [],
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
@Module(metadata)
|
|
14
|
-
export class AuthModule {
|
|
15
|
-
public static readonly path = '/auth';
|
|
16
|
-
|
|
17
|
-
public static readonly module = AuthModule;
|
|
18
|
-
|
|
19
|
-
public static readonly children = metadata.imports;
|
|
20
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Controller, Get, Inject, Param } from '@nestjs/common';
|
|
2
|
-
import { ApiTags } from '@nestjs/swagger';
|
|
3
|
-
import { OrganizationRepository } from './organization.repository';
|
|
4
|
-
|
|
5
|
-
@Controller('/')
|
|
6
|
-
@ApiTags('auth')
|
|
7
|
-
export class OrganizationController {
|
|
8
|
-
@Inject()
|
|
9
|
-
protected readonly $repository: OrganizationRepository;
|
|
10
|
-
|
|
11
|
-
@Get('/')
|
|
12
|
-
public find() {
|
|
13
|
-
return this.$repository.find();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
@Get('/:id')
|
|
17
|
-
public read(@Param('id') id: string) {
|
|
18
|
-
return this.$repository.read(id);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
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 { $collection, AbstractEntity } from '../../../abstracts/abstract.entity';
|
|
5
|
-
|
|
6
|
-
@Collection($collection)
|
|
7
|
-
export class OrganizationEntity extends AbstractEntity {
|
|
8
|
-
@Prop({ required: true, type: Schema.Types.String, unique: true })
|
|
9
|
-
public auth0: string;
|
|
10
|
-
|
|
11
|
-
@Prop({ required: true, type: Schema.Types.String, unique: true })
|
|
12
|
-
public name: string;
|
|
13
|
-
|
|
14
|
-
@Prop({ required: true, type: Schema.Types.String })
|
|
15
|
-
public displayName: string;
|
|
16
|
-
|
|
17
|
-
@Prop({ required: true, type: Schema.Types.Mixed })
|
|
18
|
-
public metadata: Record<string, any>;
|
|
19
|
-
|
|
20
|
-
@Prop({ required: true, type: Schema.Types.String })
|
|
21
|
-
public logoUrl: string;
|
|
22
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Module, ModuleMetadata } from '@nestjs/common';
|
|
2
|
-
import { AbstractRouter } from '../../../abstracts/abstract.router';
|
|
3
|
-
import { Auth0Service } from '../../../services/auth0.service';
|
|
4
|
-
import { OrganizationController } from './organization.controller';
|
|
5
|
-
import { OrganizationRepository } from './organization.repository';
|
|
6
|
-
|
|
7
|
-
export const metadata: ModuleMetadata = {
|
|
8
|
-
controllers: [OrganizationController],
|
|
9
|
-
exports: [OrganizationRepository],
|
|
10
|
-
imports: [],
|
|
11
|
-
providers: [OrganizationRepository, Auth0Service],
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
@Module(metadata)
|
|
15
|
-
export class OrganizationModule extends AbstractRouter {
|
|
16
|
-
public static readonly module = OrganizationModule;
|
|
17
|
-
|
|
18
|
-
public static readonly path = '/organization';
|
|
19
|
-
|
|
20
|
-
public static readonly children = metadata.imports;
|
|
21
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Inject, Injectable } from '@nestjs/common';
|
|
2
|
-
import { Auth0Service } from '../../../services/auth0.service';
|
|
3
|
-
|
|
4
|
-
@Injectable()
|
|
5
|
-
export class OrganizationRepository {
|
|
6
|
-
@Inject()
|
|
7
|
-
public readonly $auth0: Auth0Service;
|
|
8
|
-
|
|
9
|
-
public find() {
|
|
10
|
-
return this.$auth0.organizations.find();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public read(id: string) {
|
|
14
|
-
return this.$auth0.organizations.read(id);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { SchemaFactory } from '@nestjs/mongoose';
|
|
2
|
-
import { OrganizationEntity } from './organization.entity';
|
|
3
|
-
|
|
4
|
-
export namespace OrganizationSchema {
|
|
5
|
-
export const name = 'auth_organization';
|
|
6
|
-
|
|
7
|
-
export const schema = SchemaFactory.createForClass(OrganizationEntity);
|
|
8
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Controller, Get, Inject, Param, 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 { UserEntity } from './user.entity';
|
|
6
|
-
import { UserRepository } from './user.repository';
|
|
7
|
-
|
|
8
|
-
@Controller('/')
|
|
9
|
-
@ApiTags('auth')
|
|
10
|
-
export class UserController extends AbstractController {
|
|
11
|
-
@Inject()
|
|
12
|
-
protected readonly $repository: UserRepository;
|
|
13
|
-
|
|
14
|
-
@Get('/')
|
|
15
|
-
public find(@Query() validator: FindValidator<UserEntity>) {
|
|
16
|
-
return this.$repository.find(validator);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@Get('/:id')
|
|
20
|
-
public read(@Param() { id }: IdMongoValidator, @Query() validator?: ReadValidator) {
|
|
21
|
-
return this.$repository.read(id, validator);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
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 { $collection, AbstractEntity } from '../../../abstracts/abstract.entity';
|
|
5
|
-
|
|
6
|
-
@Collection($collection)
|
|
7
|
-
export class UserEntity extends AbstractEntity {
|
|
8
|
-
@Prop({ required: true, type: Schema.Types.String, unique: true })
|
|
9
|
-
public auth0: string;
|
|
10
|
-
|
|
11
|
-
@Prop({ required: true, type: Schema.Types.String, unique: true })
|
|
12
|
-
public email: string;
|
|
13
|
-
|
|
14
|
-
@Prop({ required: true, type: Schema.Types.String })
|
|
15
|
-
public name: string;
|
|
16
|
-
|
|
17
|
-
@Prop({ required: true, type: Schema.Types.String })
|
|
18
|
-
public picture: string;
|
|
19
|
-
|
|
20
|
-
@Prop({ required: true, type: Schema.Types.String })
|
|
21
|
-
public locale: string;
|
|
22
|
-
|
|
23
|
-
@Prop({ default: () => new Date(), type: Schema.Types.Date })
|
|
24
|
-
public lastSeen: Date;
|
|
25
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Module, type ModuleMetadata } from '@nestjs/common';
|
|
2
|
-
import { Auth0Service } from '../../../services/auth0.service';
|
|
3
|
-
import { UserController } from './user.controller';
|
|
4
|
-
import { UserRepository } from './user.repository';
|
|
5
|
-
|
|
6
|
-
const metadata: ModuleMetadata = {
|
|
7
|
-
controllers: [UserController],
|
|
8
|
-
exports: [UserRepository],
|
|
9
|
-
imports: [],
|
|
10
|
-
providers: [UserRepository, Auth0Service],
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
@Module(metadata)
|
|
14
|
-
export class UserModule {
|
|
15
|
-
public static readonly path = '/users';
|
|
16
|
-
|
|
17
|
-
public static readonly module = UserModule;
|
|
18
|
-
|
|
19
|
-
public static readonly children = metadata.imports;
|
|
20
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
2
|
-
import { InjectModel } from '@nestjs/mongoose';
|
|
3
|
-
import { Model } from 'mongoose';
|
|
4
|
-
import { AbstractRepository } from '../../../abstracts/abstarct.repository';
|
|
5
|
-
import { DecodedUser } from '../../../decorators/user.decorator';
|
|
6
|
-
import { UserEntity } from './user.entity';
|
|
7
|
-
import { UserSchema } from './user.schema';
|
|
8
|
-
import { CreateUserValidator, UpdatedUserValidator } from './user.validator';
|
|
9
|
-
|
|
10
|
-
@Injectable()
|
|
11
|
-
export class UserRepository extends AbstractRepository<UserEntity> {
|
|
12
|
-
@InjectModel(UserSchema.name)
|
|
13
|
-
protected readonly $model: Model<UserEntity>;
|
|
14
|
-
|
|
15
|
-
public async create(validator: CreateUserValidator) {
|
|
16
|
-
const user = new this.$model();
|
|
17
|
-
|
|
18
|
-
user.auth0 = validator.auth0;
|
|
19
|
-
user.name = validator.name;
|
|
20
|
-
user.email = validator.email.toLowerCase();
|
|
21
|
-
user.picture = validator.picture;
|
|
22
|
-
user.locale = validator.locale;
|
|
23
|
-
|
|
24
|
-
await user.save();
|
|
25
|
-
|
|
26
|
-
return user;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public async update(id: string, validator: UpdatedUserValidator) {
|
|
30
|
-
const user = await this.read(id);
|
|
31
|
-
|
|
32
|
-
user.name = validator.name || user.name;
|
|
33
|
-
user.picture = validator.picture || user.picture;
|
|
34
|
-
user.locale = validator.locale || user.locale;
|
|
35
|
-
user.lastSeen = new Date();
|
|
36
|
-
|
|
37
|
-
await user.save();
|
|
38
|
-
|
|
39
|
-
return user;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public async upsert(decodedUser: DecodedUser) {
|
|
43
|
-
let foundedUser: UserEntity;
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
foundedUser = await this.readByAuth0(decodedUser.sub);
|
|
47
|
-
} catch (e: unknown) {}
|
|
48
|
-
|
|
49
|
-
if (!foundedUser) {
|
|
50
|
-
const validator: CreateUserValidator = {
|
|
51
|
-
auth0: decodedUser.sub,
|
|
52
|
-
email: decodedUser.email,
|
|
53
|
-
locale: decodedUser.locale,
|
|
54
|
-
name: decodedUser.name,
|
|
55
|
-
picture: decodedUser.picture,
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
return this.create(validator);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const validator: UpdatedUserValidator = {
|
|
62
|
-
locale: decodedUser.locale,
|
|
63
|
-
name: decodedUser.name,
|
|
64
|
-
picture: decodedUser.picture,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
return this.update(foundedUser._id, validator);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public async readByAuth0(auth0: string): Promise<UserEntity> {
|
|
71
|
-
const user = await this.$model.findOne({ auth0 });
|
|
72
|
-
|
|
73
|
-
if (!user) {
|
|
74
|
-
throw new NotFoundException();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return user;
|
|
78
|
-
}
|
|
79
|
-
}
|