Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/typeorm": "^10.0.0",
"@nestjs/typeorm": "^10.0.2",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"nestjs-i18n": "^10.5.1",
"pg": "^8.11.3",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
"typeorm": "^0.3.17"
"typeorm": "^0.3.27"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
Expand Down
3 changes: 1 addition & 2 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
Expand All @@ -16,7 +15,6 @@ import { User } from './users/entities/user.entity';
ConfigModule.forRoot({
isGlobal: true,
}),

TypeOrmModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
Expand All @@ -31,6 +29,7 @@ import { User } from './users/entities/user.entity';
}),
inject: [ConfigService],
}),

AssetCategoriesModule,
DepartmentsModule,
AssetTransfersModule,
Expand Down
21 changes: 21 additions & 0 deletions backend/src/suppliers/dto/create-supplier.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator';

export class CreateSupplierDto {
@IsString()
@IsNotEmpty()
name: string;

@IsOptional()
@IsString()
contactInfo?: string;

@IsOptional()
@IsString()
address?: string;

@IsEmail()
email: string;

@IsString()
phone: string;
}
4 changes: 4 additions & 0 deletions backend/src/suppliers/dto/update-supplier.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateSupplierDto } from './create-supplier.dto';

export class UpdateSupplierDto extends PartialType(CreateSupplierDto) {}
26 changes: 26 additions & 0 deletions backend/src/suppliers/entities/supplier.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';

@Entity('suppliers')
export class Supplier {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column()
name: string;

@Column({ nullable: true })
contactInfo: string;

@Column({ nullable: true })
address: string;

@Column({ unique: true })
email: string;

@Column()
phone: string;

// This should be uncommented when the Asset entity is created
// @OneToMany(() => Asset, (asset) => asset.supplier)
// assets: Asset[];
}
42 changes: 42 additions & 0 deletions backend/src/suppliers/suppliers.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
Controller,
Get,
Post,
Body,
Param,
Put,
Delete,
} from '@nestjs/common';
import { SuppliersService } from './suppliers.service';
import { CreateSupplierDto } from './dto/create-supplier.dto';
import { UpdateSupplierDto } from './dto/update-supplier.dto';

@Controller('suppliers')
export class SuppliersController {
constructor(private readonly suppliersService: SuppliersService) {}

@Post()
create(@Body() dto: CreateSupplierDto) {
return this.suppliersService.create(dto);
}

@Get()
findAll() {
return this.suppliersService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.suppliersService.findOne(id);
}

@Put(':id')
update(@Param('id') id: string, @Body() dto: UpdateSupplierDto) {
return this.suppliersService.update(id, dto);
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.suppliersService.remove(id);
}
}
12 changes: 12 additions & 0 deletions backend/src/suppliers/suppliers.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { SuppliersService } from './suppliers.service';
import { SuppliersController } from './suppliers.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Supplier } from './entities/supplier.entity';

@Module({
imports: [TypeOrmModule.forFeature([Supplier])],
controllers: [SuppliersController],
providers: [SuppliersService],
})
export class SuppliersModule {}
42 changes: 42 additions & 0 deletions backend/src/suppliers/suppliers.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CreateSupplierDto } from './dto/create-supplier.dto';
import { UpdateSupplierDto } from './dto/update-supplier.dto';
import { Supplier } from './entities/supplier.entity';

@Injectable()
export class SuppliersService {
constructor(
@InjectRepository(Supplier)
private suppliersRepo: Repository<Supplier>,
) {}

create(dto: CreateSupplierDto): Promise<Supplier> {
const supplier = this.suppliersRepo.create(dto);
return this.suppliersRepo.save(supplier);
}

findAll(): Promise<Supplier[]> {
return this.suppliersRepo.find({ relations: ['assets'] });
}

public async findOne(id: string): Promise<Supplier> {
const supplier = await this.suppliersRepo.findOne({
where: { id },
relations: ['assets'],
});
if (!supplier) throw new NotFoundException(`Supplier ${id} not found`);
return supplier;
}

public async update(id: string, dto: UpdateSupplierDto): Promise<Supplier> {
const supplier = await this.findOne(id);
Object.assign(supplier, dto);
return this.suppliersRepo.save(supplier);
}

public async remove(id: string): Promise<void> {
await this.suppliersRepo.delete(id);
}
}