add: progress authentication
This commit is contained in:
parent
5bbb650acd
commit
2b5abc7689
|
@ -25,13 +25,16 @@
|
||||||
"@nestjs/config": "^1.0.1",
|
"@nestjs/config": "^1.0.1",
|
||||||
"@nestjs/core": "^8.0.0",
|
"@nestjs/core": "^8.0.0",
|
||||||
"@nestjs/mapped-types": "*",
|
"@nestjs/mapped-types": "*",
|
||||||
|
"@nestjs/passport": "^8.0.1",
|
||||||
"@nestjs/platform-express": "^8.0.0",
|
"@nestjs/platform-express": "^8.0.0",
|
||||||
"@nestjs/platform-fastify": "^8.0.8",
|
"@nestjs/platform-fastify": "^8.0.8",
|
||||||
"@nestjs/typeorm": "^8.0.2",
|
"@nestjs/typeorm": "^8.0.2",
|
||||||
"class-transformer": "^0.4.0",
|
"class-transformer": "^0.4.0",
|
||||||
"class-validator": "^0.13.1",
|
"class-validator": "^0.13.1",
|
||||||
|
"crypto": "^1.0.1",
|
||||||
"joi": "^17.4.2",
|
"joi": "^17.4.2",
|
||||||
"nestjs-pino": "^2.3.1",
|
"nestjs-pino": "^2.3.1",
|
||||||
|
"passport-jwt": "^4.0.0",
|
||||||
"pg": "^8.7.1",
|
"pg": "^8.7.1",
|
||||||
"pino-http": "^6.3.0",
|
"pino-http": "^6.3.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { LoggerModule } from 'nestjs-pino';
|
||||||
import { TransactionModule } from './transaction/transaction.module';
|
import { TransactionModule } from './transaction/transaction.module';
|
||||||
import { ProductModule } from './product/product.module';
|
import { ProductModule } from './product/product.module';
|
||||||
import { ConfigurableModule } from './configurable/configurable.module';
|
import { ConfigurableModule } from './configurable/configurable.module';
|
||||||
|
import { AuthModule } from './auth/auth.module';
|
||||||
import configuration from './config/configuration';
|
import configuration from './config/configuration';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
|
@ -50,6 +51,7 @@ import configuration from './config/configuration';
|
||||||
UsersModule,
|
UsersModule,
|
||||||
TransactionModule,
|
TransactionModule,
|
||||||
ConfigurableModule,
|
ConfigurableModule,
|
||||||
|
AuthModule,
|
||||||
// ProductModule,
|
// ProductModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
9
src/auth/dto/input-login.dto.ts
Normal file
9
src/auth/dto/input-login.dto.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import { IsNotEmpty } from 'class-validator';
|
||||||
|
|
||||||
|
export class InputLoginDto {
|
||||||
|
@IsNotEmpty()
|
||||||
|
username: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
password: string;
|
||||||
|
}
|
9
src/auth/dto/response-login.dto.ts
Normal file
9
src/auth/dto/response-login.dto.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import { IsNotEmpty } from 'class-validator';
|
||||||
|
|
||||||
|
export class ResponseLoginDto {
|
||||||
|
@IsNotEmpty()
|
||||||
|
username: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
jwt: string;
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ import {
|
||||||
Param,
|
Param,
|
||||||
Delete,
|
Delete,
|
||||||
ParseUUIDPipe,
|
ParseUUIDPipe,
|
||||||
HttpStatus,
|
HttpStatus, Query,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ConfigurableService } from './configurable.service';
|
import { ConfigurableService } from './configurable.service';
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ export class ConfigurableController {
|
||||||
constructor(private readonly usersService: ConfigurableService) {}
|
constructor(private readonly usersService: ConfigurableService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async findAll() {
|
async findAll(@Query('page') page: number) {
|
||||||
const [data, count] = await this.usersService.findAll();
|
const [data, count] = await this.usersService.findAllRoles(page);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
|
|
|
@ -10,8 +10,14 @@ export class ConfigurableService {
|
||||||
private rolesRepository: Repository<Roles>,
|
private rolesRepository: Repository<Roles>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
findAll() {
|
findAllRoles(page) {
|
||||||
return this.rolesRepository.findAndCount();
|
return this.rolesRepository.findAndCount({
|
||||||
|
skip: page * 10,
|
||||||
|
take: 10,
|
||||||
|
order: {
|
||||||
|
version: 'DESC',
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(id: string) {
|
async findOne(id: string) {
|
||||||
|
|
10
src/helper/hash_password.ts
Normal file
10
src/helper/hash_password.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import * as crypto from 'crypto';
|
||||||
|
|
||||||
|
export function hashPassword(password, salt): Promise<string> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
crypto.pbkdf2(password, salt, 50, 100, 'sha512', (err, values) => {
|
||||||
|
if (err) return reject(err);
|
||||||
|
resolve(values.toString('hex'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
22
src/helper/jwt.strategy.ts
Normal file
22
src/helper/jwt.strategy.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import { PassportStrategy } from '@nestjs/passport';
|
||||||
|
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { AuthService } from '../auth/auth.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||||
|
constructor(private readonly authService: AuthService) {
|
||||||
|
super({
|
||||||
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||||
|
secretOrKey: process.env.SECRETKEY,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async validate(payload: JwtPayload): Promise<UserDto> {
|
||||||
|
const user = await this.authService.validateUser(payload);
|
||||||
|
if (!user) {
|
||||||
|
throw new HttpException('Invalid token', HttpStatus.UNAUTHORIZED);
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,10 @@ import {
|
||||||
UpdateDateColumn,
|
UpdateDateColumn,
|
||||||
DeleteDateColumn,
|
DeleteDateColumn,
|
||||||
VersionColumn,
|
VersionColumn,
|
||||||
CreateDateColumn, ManyToOne, ManyToMany, JoinTable,
|
CreateDateColumn,
|
||||||
|
ManyToOne,
|
||||||
|
ManyToMany,
|
||||||
|
JoinTable,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { Product } from '../../product/entities/product.entity';
|
import { Product } from '../../product/entities/product.entity';
|
||||||
import { User } from '../../users/entities/user.entity';
|
import { User } from '../../users/entities/user.entity';
|
||||||
|
@ -22,10 +25,7 @@ enum balanceType {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Roles extends BaseModel{
|
export class COA extends BaseModel {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
|
@ -1 +1,38 @@
|
||||||
export class Transaction {}
|
import {
|
||||||
|
Entity,
|
||||||
|
Column,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
|
DeleteDateColumn,
|
||||||
|
VersionColumn,
|
||||||
|
CreateDateColumn,
|
||||||
|
ManyToOne,
|
||||||
|
ManyToMany,
|
||||||
|
JoinTable,
|
||||||
|
} from 'typeorm';
|
||||||
|
import { Product } from '../../product/entities/product.entity';
|
||||||
|
import { User } from '../../users/entities/user.entity';
|
||||||
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
|
import { COA } from './coa.entity';
|
||||||
|
import { ProductHistoryPrice } from '../../product/entities/product-history-price.entity';
|
||||||
|
|
||||||
|
enum status {
|
||||||
|
PENDING,
|
||||||
|
SUCCESS,
|
||||||
|
FAILED,
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class Transaction extends BaseModel {
|
||||||
|
@Column()
|
||||||
|
amount: number;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
status: status;
|
||||||
|
|
||||||
|
@ManyToOne(() => User, (user) => user.id)
|
||||||
|
user: User;
|
||||||
|
|
||||||
|
@ManyToOne(() => ProductHistoryPrice, (productHistory) => productHistory.id)
|
||||||
|
product: ProductHistoryPrice;
|
||||||
|
}
|
||||||
|
|
36
src/transaction/entities/transaction_journal.entity.ts
Normal file
36
src/transaction/entities/transaction_journal.entity.ts
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
import {
|
||||||
|
Entity,
|
||||||
|
Column,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
|
DeleteDateColumn,
|
||||||
|
VersionColumn,
|
||||||
|
CreateDateColumn, ManyToOne, ManyToMany, JoinTable,
|
||||||
|
} from 'typeorm';
|
||||||
|
import { Product } from '../../product/entities/product.entity';
|
||||||
|
import { User } from '../../users/entities/user.entity';
|
||||||
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
|
import { ProductCategories } from '../../product/entities/product-category.entity';
|
||||||
|
import { COA } from './coa.entity';
|
||||||
|
|
||||||
|
enum type {
|
||||||
|
SYSTEM_BANk,
|
||||||
|
INCOME,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum balanceType {
|
||||||
|
DEBIT,
|
||||||
|
CREDIT,
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class TransactionJournal extends BaseModel {
|
||||||
|
@Column('text')
|
||||||
|
type: type;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
amount: number;
|
||||||
|
|
||||||
|
@ManyToOne(() => COA, (coa) => coa.id)
|
||||||
|
coa: COA;
|
||||||
|
}
|
|
@ -1,45 +1,25 @@
|
||||||
import {
|
import {
|
||||||
Entity,
|
Entity,
|
||||||
Column,
|
Column,
|
||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn, BeforeInsert,
|
||||||
UpdateDateColumn,
|
|
||||||
DeleteDateColumn,
|
|
||||||
VersionColumn,
|
|
||||||
CreateDateColumn,
|
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
|
import { hashPassword } from '../../helper/hash_password';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class User {
|
export class User extends BaseModel {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
firstName: string;
|
username: string;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
lastName: string;
|
password: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
salt: string;
|
||||||
|
|
||||||
@Column({ default: true })
|
@Column({ default: true })
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
|
|
||||||
@CreateDateColumn({
|
|
||||||
type: 'timestamp with time zone',
|
|
||||||
nullable: false,
|
|
||||||
})
|
|
||||||
createdAt: Date;
|
|
||||||
|
|
||||||
@UpdateDateColumn({
|
|
||||||
type: 'timestamp with time zone',
|
|
||||||
nullable: false,
|
|
||||||
})
|
|
||||||
updatedAt: Date;
|
|
||||||
|
|
||||||
@DeleteDateColumn({
|
|
||||||
type: 'timestamp with time zone',
|
|
||||||
nullable: true,
|
|
||||||
})
|
|
||||||
deletedAt: Date;
|
|
||||||
|
|
||||||
@VersionColumn()
|
|
||||||
version: number;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user