Skip to content

Commit

Permalink
18 Desember 08.18
Browse files Browse the repository at this point in the history
  • Loading branch information
chandra2525 committed Dec 18, 2024
1 parent 7fd95a4 commit e48a4bd
Show file tree
Hide file tree
Showing 823 changed files with 2,808 additions and 109,366 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified backend/.DS_Store
Binary file not shown.
70 changes: 37 additions & 33 deletions backend/package-lock.json

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

4 changes: 4 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { AssetChangeLogModule } from './assetChangeLog/assetChangeLog.module';
import { AssetToolCategoryModule } from './assetToolCategory/assetToolCategory.module';
import { AssetToolConditionModule } from './assetToolCondition/assetToolCondition.module';
import { AssetUnitModule } from './assetUnit/assetUnit.module';
import { LoanModule } from './loan/loan.module';
import { LoanAssetModule } from './loanAsset/loanAsset.module';
import { databaseConfig } from './config/database.config';

@Module({
Expand All @@ -25,6 +27,8 @@ import { databaseConfig } from './config/database.config';
AssetToolCategoryModule,
AssetToolConditionModule,
AssetUnitModule,
LoanModule,
LoanAssetModule,
],
})
export class AppModule {}
20 changes: 20 additions & 0 deletions backend/src/asset/asset.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ export class AssetController {
@Get('getAssetsCategory')
async getAssetsCategory() {
return this.assetService.getAssetsCategory();
}

@Get('getAssetsName')
async getAssetsName(
@Query('category') category?: string,
@Query('order_by') orderBy?: string,
@Query('order_direction') orderDirection?: 'ASC' | 'DESC',
@Query('search') search?: string,
@Query('page') page: number = 1,
@Query('pageSize') pageSize: number = 10,
// ): Promise<AssetUnit[]> {
) {
return this.assetService.getAssetsName(
category,
orderBy,
orderDirection,
search,
page,
pageSize,
); // Panggil logika filter
}

// @Get('getAssetsToolCategory')
Expand Down
6 changes: 5 additions & 1 deletion backend/src/asset/asset.model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Table, Column, Model, DataType, ForeignKey, BelongsTo } from 'sequelize-typescript';
import { Table, Column, Model, DataType, ForeignKey, BelongsTo, HasMany } from 'sequelize-typescript';
import { Branch } from '../branch/branch.model';
import { AssetToolCategory } from '../assetToolCategory/assetToolCategory.model';
import { AssetToolCondition } from '../assetToolCondition/assetToolCondition.model';
import { AssetUnit } from '../assetUnit/assetUnit.model';
import { LoanAsset } from 'src/loanAsset/loanAsset.model';


// @Table
Expand Down Expand Up @@ -63,5 +64,8 @@ export class Asset extends Model<Asset> {
@BelongsTo(() => AssetUnit)
assetUnit: AssetUnit;

@HasMany(() => LoanAsset)
loanAsset: LoanAsset[];

}

44 changes: 44 additions & 0 deletions backend/src/asset/asset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,50 @@ export class AssetService {
return assetsCategory.map(asset => asset.category);
}


async getAssetsName(
category?: string,
orderBy: string = 'asset_id',
orderDirection: 'ASC' | 'DESC' = 'DESC',
search?: string,
page: number = 1,
pageSize: number = 10,
): Promise<{ rows: Asset[]; sp: any }> {
const whereClause: any = {};

if (category) {
whereClause.category = { [Op.iLike]: `%${category}%` };
}

if (search) {
whereClause[Op.or] = [
{ asset_name: { [Op.iLike]: `%${search}%` } },
];
}

// Pagination variables
const offset = (page - 1) * pageSize;
const limit = pageSize;

const { rows, count } = await this.assetModel.findAndCountAll({
attributes: ['asset_id', 'asset_name'],
where: whereClause,
order: [[orderBy, orderDirection]],
offset,
limit,
});

const sp = {
page,
pageSize,
pageCount: Math.ceil(count / pageSize),
rowCount: count,
start: offset,
limit,
};

return { rows, sp };
}
// async getAssetsToolCategory(): Promise<string[]> {
// const assetsToolCategory = await this.assetModel.findAll({
// attributes: ['tool_category'],
Expand Down
27 changes: 27 additions & 0 deletions backend/src/loan/loan.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Controller, Get, Post, Put, Delete, Body, Param, UseGuards, Query, UploadedFile, UseInterceptors, Res, HttpException, HttpStatus, BadRequestException } from '@nestjs/common';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { LoanService } from './loan.service';
import { Loan } from './loan.model';
import { FileInterceptor } from '@nestjs/platform-express';
import * as multer from 'multer';
import { Response } from 'express';
import { CreateLoanDto } from './loan.dto';

export class TemplateQueryDto {
// @IsOptional()
// @IsString()
format?: string; // Contoh opsi tambahan, misalnya format file (xls/xlsx)
}

@Controller('loan')
@UseGuards(JwtAuthGuard)
export class LoanController {
constructor(private readonly loanService: LoanService) {}

@Post()
async create(@Body() createLoanDto: CreateLoanDto) {
return await this.loanService.createLoan(createLoanDto);
}

}

10 changes: 10 additions & 0 deletions backend/src/loan/loan.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export class CreateLoanDto {
user_id: number;
customer_name: string;
notes: string;
assets: {
asset_id: number;
input_method: string;
quantity: number;
}[];
}
24 changes: 24 additions & 0 deletions backend/src/loan/loan.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Table, Column, Model, DataType, HasMany } from 'sequelize-typescript';
import { LoanAsset } from 'src/loanAsset/loanAsset.model';

// @Table
@Table({
tableName: 'loan',
timestamps: false // Menonaktifkan createdAt dan updatedAt
})
export class Loan extends Model<Loan> {
@Column({ type: DataType.INTEGER, primaryKey: true, autoIncrement: true })
loan_id: number;

@Column({ type: DataType.INTEGER, allowNull: false })
user_id: number;

@Column({ type: DataType.STRING, allowNull: false })
customer_name: string;

@Column({ type: DataType.STRING, allowNull: false })
notes: string;

@HasMany(() => LoanAsset)
loanAsset: LoanAsset[];
}
15 changes: 15 additions & 0 deletions backend/src/loan/loan.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Module } from '@nestjs/common';
import { SequelizeModule } from '@nestjs/sequelize';
import { LoanController } from './loan.controller';
import { LoanService } from './loan.service';
import { Loan } from './loan.model';
import { LoanAsset } from 'src/loanAsset/loanAsset.model';


@Module({
imports: [SequelizeModule.forFeature([Loan, LoanAsset])],
controllers: [LoanController],
providers: [LoanService],
exports: [LoanService],
})
export class LoanModule {}
Loading

0 comments on commit e48a4bd

Please sign in to comment.