feat(SPG-496) Model Users
parent
b945ef1e10
commit
c0b0ffa8fa
|
@ -0,0 +1,21 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class User1717401535006 implements MigrationInterface {
|
||||||
|
name = 'User1717401535006';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TABLE "users" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "creator_id" character varying(36), "creator_name" character varying(125), "editor_id" character varying(36), "editor_name" character varying(125), "created_at" bigint NOT NULL, "updated_at" bigint NOT NULL, "status" "public"."users_status_enum" NOT NULL DEFAULT 'draft', "refresh_token" character varying, "name" character varying, "username" character varying, "password" character varying, "email" character varying, "role" "public"."users_role_enum" NOT NULL DEFAULT 'staff', "user_privilege_id" uuid, CONSTRAINT "PK_a3ffb1c0c8416b9fc6f907b7433" PRIMARY KEY ("id"))`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "users" ADD CONSTRAINT "FK_a575428fc6718f1394eff0d8443" FOREIGN KEY ("user_privilege_id") REFERENCES "user_privileges"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "users" DROP CONSTRAINT "FK_a575428fc6718f1394eff0d8443"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(`DROP TABLE "users"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
export enum UserRole {
|
||||||
|
SUPERADMIN = 'superadmin',
|
||||||
|
STAFF = 'staff',
|
||||||
|
TENANT = 'tenant',
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
|
||||||
|
import { UserEntity } from '../../domain/entities/user.entity';
|
||||||
|
import { UserRole } from '../../constants';
|
||||||
|
import { UserPrivilegeModel } from 'src/modules/user-related/user-privilege/data/models/user-privilege.model';
|
||||||
|
|
||||||
|
@Entity(TABLE_NAME.USER)
|
||||||
|
export class UserModel
|
||||||
|
extends BaseStatusModel<UserEntity>
|
||||||
|
implements UserEntity
|
||||||
|
{
|
||||||
|
@Column('varchar', { name: 'refresh_token', nullable: true })
|
||||||
|
refresh_token: string;
|
||||||
|
|
||||||
|
@Column('varchar', { name: 'name', nullable: true })
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@Column('varchar', { name: 'username', nullable: true })
|
||||||
|
username: string;
|
||||||
|
|
||||||
|
@Column('varchar', { name: 'password', nullable: true })
|
||||||
|
password: string;
|
||||||
|
|
||||||
|
@Column('varchar', { name: 'email', nullable: true })
|
||||||
|
email: string;
|
||||||
|
|
||||||
|
@Column('enum', { name: 'role', enum: UserRole, default: UserRole.STAFF })
|
||||||
|
role: UserRole;
|
||||||
|
|
||||||
|
@Column('varchar', { name: 'user_privilege_id', nullable: true })
|
||||||
|
user_privilege_id: string;
|
||||||
|
@ManyToOne(() => UserPrivilegeModel, (model) => model.users, {
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
onUpdate: 'CASCADE',
|
||||||
|
})
|
||||||
|
@JoinColumn({ name: 'user_privilege_id' })
|
||||||
|
user_privilege: UserPrivilegeModel;
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
||||||
|
import { UserEntity } from '../../domain/entities/user.entity';
|
||||||
|
import { UserModel } from '../models/user.model';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class UserDataService extends BaseDataService<UserEntity> {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(UserModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private repo: Repository<UserModel>,
|
||||||
|
) {
|
||||||
|
super(repo);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
||||||
|
import { UserEntity } from '../../domain/entities/user.entity';
|
||||||
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { UserModel } from '../models/user.model';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class UserReadService extends BaseReadService<UserEntity> {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(UserModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private repo: Repository<UserModel>,
|
||||||
|
) {
|
||||||
|
super(repo);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.entity';
|
||||||
|
import { UserRole } from '../../constants';
|
||||||
|
|
||||||
|
export interface UserEntity extends BaseStatusEntity {
|
||||||
|
name: string;
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
email: string;
|
||||||
|
role: UserRole;
|
||||||
|
refresh_token: string;
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { CqrsModule } from '@nestjs/cqrs';
|
||||||
|
import { UserModel } from './data/models/user.model';
|
||||||
|
import { UserReadService } from './data/services.ts/user-read.service';
|
||||||
|
import { UserDataService } from './data/services.ts/user-data.service';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
ConfigModule.forRoot(),
|
||||||
|
TypeOrmModule.forFeature([UserModel], CONNECTION_NAME.DEFAULT),
|
||||||
|
CqrsModule,
|
||||||
|
],
|
||||||
|
controllers: [],
|
||||||
|
providers: [UserReadService, UserDataService],
|
||||||
|
exports: [UserDataService],
|
||||||
|
})
|
||||||
|
export class UserModule {}
|
Loading…
Reference in New Issue