add: add modules entity
This commit is contained in:
parent
770231744d
commit
288a6e5b69
36
src/config/basemodel.entity.ts
Normal file
36
src/config/basemodel.entity.ts
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
import {
|
||||||
|
Entity,
|
||||||
|
Column,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
|
DeleteDateColumn,
|
||||||
|
VersionColumn,
|
||||||
|
CreateDateColumn,
|
||||||
|
} from 'typeorm';
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class BaseModel {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
20
src/configurable/configurable.controller.spec.ts
Normal file
20
src/configurable/configurable.controller.spec.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { ConfigurableController } from './configurable.controller';
|
||||||
|
import { ConfigurableService } from './configurable.service';
|
||||||
|
|
||||||
|
describe('ConfigurableController', () => {
|
||||||
|
let controller: ConfigurableController;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [ConfigurableController],
|
||||||
|
providers: [ConfigurableService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
controller = module.get<ConfigurableController>(ConfigurableController);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(controller).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
42
src/configurable/configurable.controller.ts
Normal file
42
src/configurable/configurable.controller.ts
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
Post,
|
||||||
|
Body,
|
||||||
|
Put,
|
||||||
|
Param,
|
||||||
|
Delete,
|
||||||
|
ParseUUIDPipe,
|
||||||
|
HttpStatus,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { ConfigurableService } from './configurable.service';
|
||||||
|
|
||||||
|
@Controller({
|
||||||
|
path: 'config',
|
||||||
|
version: '1',
|
||||||
|
})
|
||||||
|
export class ConfigurableController {
|
||||||
|
constructor(private readonly usersService: ConfigurableService) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
async findAll() {
|
||||||
|
const [data, count] = await this.usersService.findAll();
|
||||||
|
|
||||||
|
return {
|
||||||
|
data,
|
||||||
|
count,
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
async findOne(@Param('id', ParseUUIDPipe) id: string) {
|
||||||
|
return {
|
||||||
|
data: await this.usersService.findOne(id),
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
12
src/configurable/configurable.module.ts
Normal file
12
src/configurable/configurable.module.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { Roles } from './entities/roles.entity';
|
||||||
|
import { ConfigurableController } from './configurable.controller';
|
||||||
|
import { ConfigurableService } from './configurable.service';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [TypeOrmModule.forFeature([Roles])],
|
||||||
|
controllers: [ConfigurableController],
|
||||||
|
providers: [ConfigurableService],
|
||||||
|
})
|
||||||
|
export class ConfigurableModule {}
|
18
src/configurable/configurable.service.spec.ts
Normal file
18
src/configurable/configurable.service.spec.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { ConfigurableService } from './configurable.service';
|
||||||
|
|
||||||
|
describe('ConfigurableService', () => {
|
||||||
|
let service: ConfigurableService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [ConfigurableService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
service = module.get<ConfigurableService>(ConfigurableService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(service).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
34
src/configurable/configurable.service.ts
Normal file
34
src/configurable/configurable.service.ts
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||||
|
import { EntityNotFoundError, Repository } from 'typeorm';
|
||||||
|
import { Roles } from './entities/roles.entity';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ConfigurableService {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(Roles)
|
||||||
|
private rolesRepository: Repository<Roles>,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
findAll() {
|
||||||
|
return this.rolesRepository.findAndCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
async findOne(id: string) {
|
||||||
|
try {
|
||||||
|
return await this.rolesRepository.findOneOrFail(id);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
|
error: 'Data not found',
|
||||||
|
},
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
src/configurable/entities/roles.entity.ts
Normal file
8
src/configurable/entities/roles.entity.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import { Entity, Column } from 'typeorm';
|
||||||
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class Roles extends BaseModel {
|
||||||
|
@Column()
|
||||||
|
name: string;
|
||||||
|
}
|
44
src/ledger/entities/coa.entity.ts
Normal file
44
src/ledger/entities/coa.entity.ts
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
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';
|
||||||
|
|
||||||
|
enum type {
|
||||||
|
SYSTEM_BANk,
|
||||||
|
INCOME,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum balanceType {
|
||||||
|
DEBIT,
|
||||||
|
CREDIT,
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class Roles extends BaseModel{
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@Column('text')
|
||||||
|
type: type;
|
||||||
|
|
||||||
|
@Column('text')
|
||||||
|
balanceType: balanceType;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
amount: number;
|
||||||
|
|
||||||
|
@ManyToMany(() => User)
|
||||||
|
@JoinTable()
|
||||||
|
user: User[];
|
||||||
|
}
|
33
src/product/entities/product.entity.ts
Normal file
33
src/product/entities/product.entity.ts
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import {
|
||||||
|
Entity,
|
||||||
|
Column,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
|
DeleteDateColumn,
|
||||||
|
VersionColumn,
|
||||||
|
CreateDateColumn,
|
||||||
|
OneToMany,
|
||||||
|
} from 'typeorm';
|
||||||
|
import { ProductSubCategories } from './productSubCategory.entity';
|
||||||
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class Product extends BaseModel{
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
code: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
status: string;
|
||||||
|
|
||||||
|
@OneToMany(
|
||||||
|
() => ProductSubCategories,
|
||||||
|
(subCategories) => subCategories.category,
|
||||||
|
)
|
||||||
|
subCategories: ProductSubCategories;
|
||||||
|
}
|
27
src/product/entities/productCategory.entity.ts
Normal file
27
src/product/entities/productCategory.entity.ts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import {
|
||||||
|
Entity,
|
||||||
|
Column,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
|
DeleteDateColumn,
|
||||||
|
VersionColumn,
|
||||||
|
CreateDateColumn,
|
||||||
|
OneToMany,
|
||||||
|
} from 'typeorm';
|
||||||
|
import { ProductSubCategories } from './productSubCategory.entity';
|
||||||
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class ProductCategories extends BaseModel {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@OneToMany(
|
||||||
|
() => ProductSubCategories,
|
||||||
|
(subCategories) => subCategories.category,
|
||||||
|
)
|
||||||
|
subCategories: ProductSubCategories;
|
||||||
|
}
|
36
src/product/entities/productHistoryPrice.entity.ts
Normal file
36
src/product/entities/productHistoryPrice.entity.ts
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
import {
|
||||||
|
Entity,
|
||||||
|
Column,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
|
DeleteDateColumn,
|
||||||
|
VersionColumn,
|
||||||
|
CreateDateColumn,
|
||||||
|
OneToMany,
|
||||||
|
ManyToOne,
|
||||||
|
} from 'typeorm';
|
||||||
|
import { Product } from './product.entity';
|
||||||
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
|
|
||||||
|
enum Type {
|
||||||
|
NORMAL,
|
||||||
|
PROMO,
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class ProductHistoryPrice extends BaseModel {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@ManyToOne(() => Product, (product) => product.id)
|
||||||
|
productId: string;
|
||||||
|
|
||||||
|
@Column({ type: 'date' })
|
||||||
|
startDate: string;
|
||||||
|
|
||||||
|
@Column({ type: 'date' })
|
||||||
|
endDate: string;
|
||||||
|
|
||||||
|
@Column('text')
|
||||||
|
type: Type;
|
||||||
|
}
|
24
src/product/entities/productSubCategory.entity.ts
Normal file
24
src/product/entities/productSubCategory.entity.ts
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import {
|
||||||
|
Entity,
|
||||||
|
Column,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
|
DeleteDateColumn,
|
||||||
|
VersionColumn,
|
||||||
|
CreateDateColumn,
|
||||||
|
ManyToOne,
|
||||||
|
} from 'typeorm';
|
||||||
|
import { ProductCategories } from './productCategory.entity';
|
||||||
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class ProductSubCategories extends BaseModel{
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@ManyToOne(() => ProductCategories, (categories) => categories.subCategories)
|
||||||
|
category: ProductCategories;
|
||||||
|
}
|
18
src/users/entities/userDetail.entity.ts
Normal file
18
src/users/entities/userDetail.entity.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import {
|
||||||
|
Entity,
|
||||||
|
Column,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
|
DeleteDateColumn,
|
||||||
|
VersionColumn,
|
||||||
|
CreateDateColumn,
|
||||||
|
} from 'typeorm';
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class User {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
firstName: string;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user