mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-26 01:57:53 +00:00
authentication module done
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { AbstractEntity } from '../entities/abstract.entity';
|
||||
|
||||
export class AbstractDto {
|
||||
@ApiProperty({ format: 'uuid' })
|
||||
readonly uuid: string;
|
||||
|
||||
constructor(abstract: AbstractEntity, options?: { excludeFields?: boolean }) {
|
||||
if (!options?.excludeFields) {
|
||||
this.uuid = abstract.uuid;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './abstract.dto'
|
||||
@@ -0,0 +1,47 @@
|
||||
import { Exclude } from 'class-transformer';
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Generated,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
import { AbstractDto } from '../dtos';
|
||||
import { Constructor } from '@app/common/util/types';
|
||||
|
||||
export abstract class AbstractEntity<
|
||||
T extends AbstractDto = AbstractDto,
|
||||
O = never
|
||||
> {
|
||||
@PrimaryGeneratedColumn('increment')
|
||||
@Exclude()
|
||||
public id: number;
|
||||
|
||||
@Column()
|
||||
@Generated('uuid')
|
||||
public uuid: string;
|
||||
|
||||
@CreateDateColumn({ type: 'timestamp' })
|
||||
@Exclude()
|
||||
public createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({ type: 'timestamp' })
|
||||
@Exclude()
|
||||
public updatedAt: Date;
|
||||
|
||||
private dtoClass: Constructor<T, [AbstractEntity, O?]>;
|
||||
|
||||
toDto(options?: O): T {
|
||||
const dtoClass = this.dtoClass;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
if (!dtoClass) {
|
||||
throw new Error(
|
||||
`You need to use @UseDto on class (${this.constructor.name}) be able to call toDto function`
|
||||
);
|
||||
}
|
||||
|
||||
return new this.dtoClass(this, options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user