-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6cba83
commit 74b8dc0
Showing
13 changed files
with
464 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
apps/discount-coffe/src/api/admin/all-factor-report/all-factor-report.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
Controller, | ||
Get, | ||
HttpCode, | ||
HttpStatus, | ||
Query, | ||
UseGuards, | ||
UseInterceptors, | ||
} from '@nestjs/common'; | ||
import { CheckPermission } from '@rahino/permission-checker/decorator'; | ||
import { PermissionGuard } from '@rahino/permission-checker/guard'; | ||
import { JsonResponseTransformInterceptor } from '@rahino/response/interceptor'; | ||
import { | ||
ApiBearerAuth, | ||
ApiOperation, | ||
ApiQuery, | ||
ApiTags, | ||
} from '@nestjs/swagger'; | ||
import { JwtGuard } from '@rahino/auth/guard'; | ||
import { AllFactorReportService } from './all-factor-report.service'; | ||
import { AllFactorReportDto } from './dto'; | ||
|
||
@ApiTags('DiscountCoffe-ALL-Factor-report') | ||
@ApiBearerAuth() | ||
@UseInterceptors(JsonResponseTransformInterceptor) | ||
@UseGuards(JwtGuard, PermissionGuard) | ||
@Controller({ | ||
path: '/api/discountcoffe/admin/allFactorReports', | ||
version: ['1'], | ||
}) | ||
export class AllFactorReportController { | ||
constructor(private service: AllFactorReportService) {} | ||
|
||
@ApiOperation({ description: 'show all total reserves' }) | ||
@CheckPermission({ | ||
permissionSymbol: 'discountcoffe.admin.allfactorreport.showmenu', | ||
}) | ||
@Get('/') | ||
@ApiQuery({ | ||
name: 'filter', | ||
type: AllFactorReportDto, | ||
style: 'deepObject', | ||
explode: true, | ||
}) | ||
@HttpCode(HttpStatus.OK) | ||
async findAll(@Query() filter: AllFactorReportDto) { | ||
return await this.service.findAll(filter); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
apps/discount-coffe/src/api/admin/all-factor-report/all-factor-report.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { SequelizeModule } from '@nestjs/sequelize'; | ||
import { Permission } from '@rahino/database/models/core/permission.entity'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { AllFactorReportService } from './all-factor-report.service'; | ||
import { AllFactorReportController } from './all-factor-report.controller'; | ||
import { VW_BuffetReservers } from '@rahino/database/models/discount-coffe/vw_buffet_reserve.entity'; | ||
|
||
@Module({ | ||
imports: [SequelizeModule.forFeature([User, Permission, VW_BuffetReservers])], | ||
providers: [AllFactorReportService], | ||
controllers: [AllFactorReportController], | ||
}) | ||
export class AllFactorReportApiModule {} |
26 changes: 26 additions & 0 deletions
26
apps/discount-coffe/src/api/admin/all-factor-report/all-factor-report.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectModel } from '@nestjs/sequelize'; | ||
import { QueryOptionsBuilder } from '@rahino/query-filter/sequelize-query-builder'; | ||
import * as _ from 'lodash'; | ||
import { AllFactorReportDto } from './dto'; | ||
import { VW_BuffetReservers } from '@rahino/database/models/discount-coffe/vw_buffet_reserve.entity'; | ||
|
||
@Injectable() | ||
export class AllFactorReportService { | ||
constructor( | ||
@InjectModel(VW_BuffetReservers) | ||
private readonly repository: typeof VW_BuffetReservers, | ||
) {} | ||
|
||
async findAll(filter: AllFactorReportDto) { | ||
const queryBuilder = new QueryOptionsBuilder().filter({ | ||
id: filter.buffetId, | ||
}); | ||
const count = await this.repository.count(queryBuilder.build()); | ||
const result = await this.repository.findAll(queryBuilder.build()); | ||
return { | ||
result: result, | ||
total: count, | ||
}; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
apps/discount-coffe/src/api/admin/all-factor-report/dto/all-factor-report.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { Transform } from 'class-transformer'; | ||
import { IsNumber } from 'class-validator'; | ||
|
||
export class AllFactorReportDto { | ||
@Transform(({ value }) => Math.max(Number(value), 1)) | ||
@IsNumber() | ||
@ApiProperty({ | ||
required: true, | ||
default: 10, | ||
description: 'how many item returned.', | ||
type: IsNumber, | ||
}) | ||
public buffetId: bigint; | ||
} |
1 change: 1 addition & 0 deletions
1
apps/discount-coffe/src/api/admin/all-factor-report/dto/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './all-factor-report.dto'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
apps/discount-coffe/src/controller/admin/all-factor-report/all-factor-report.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
Controller, | ||
Get, | ||
HttpCode, | ||
HttpStatus, | ||
Render, | ||
Req, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { CheckPermission } from '@rahino/permission-checker/decorator'; | ||
import { PermissionGuard } from '@rahino/permission-checker/guard'; | ||
import { JwtWebGuard } from '@rahino/auth/guard'; | ||
import { GetUser } from '@rahino/auth/decorator'; | ||
import { Menu } from '@rahino/database/models/core/menu.entity'; | ||
import { AllFactorReportService } from './all-factor-report.service'; | ||
import { Request } from 'express'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
|
||
@UseGuards(JwtWebGuard, PermissionGuard) | ||
@Controller({ | ||
path: '/discountcoffe/admin/allFactorReport', | ||
}) | ||
export class AllFactorReportController { | ||
constructor(private service: AllFactorReportService) {} | ||
@CheckPermission({ | ||
permissionSymbol: 'discountcoffe.admin.allfactorreport.showmenu', | ||
}) | ||
@Get('/') | ||
@HttpCode(HttpStatus.OK) | ||
@Render('admin/allfactorreport/index') | ||
async get( | ||
@GetUser() user: User, | ||
@GetUser('menus') menus: Menu[], | ||
@Req() req: Request, | ||
) { | ||
return await this.service.factorReport(req, user, menus); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
apps/discount-coffe/src/controller/admin/all-factor-report/all-factor-report.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { SequelizeModule } from '@nestjs/sequelize'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { Permission } from '@rahino/database/models/core/permission.entity'; | ||
import { AllFactorReportController } from './all-factor-report.controller'; | ||
import { AllFactorReportService } from './all-factor-report.service'; | ||
import { Buffet } from '@rahino/database/models/discount-coffe/buffet.entity'; | ||
|
||
@Module({ | ||
imports: [SequelizeModule.forFeature([User, Permission, Buffet])], | ||
controllers: [AllFactorReportController], | ||
providers: [AllFactorReportService], | ||
}) | ||
export class AllFactorReportModule {} |
38 changes: 38 additions & 0 deletions
38
apps/discount-coffe/src/controller/admin/all-factor-report/all-factor-report.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { BadRequestException, Injectable } from '@nestjs/common'; | ||
import { InjectModel } from '@nestjs/sequelize'; | ||
import { Menu } from '@rahino/database/models/core/menu.entity'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { Buffet } from '@rahino/database/models/discount-coffe/buffet.entity'; | ||
import { QueryOptionsBuilder } from '@rahino/query-filter/sequelize-query-builder'; | ||
import { Request } from 'express'; | ||
import { Op } from 'sequelize'; | ||
import { Sequelize } from 'sequelize'; | ||
|
||
@Injectable() | ||
export class AllFactorReportService { | ||
constructor( | ||
@InjectModel(Buffet) | ||
private readonly buffetRepository: typeof Buffet, | ||
) {} | ||
async factorReport(req: Request, user: User, menus: Menu[]) { | ||
const buffets = await this.buffetRepository.findAll( | ||
new QueryOptionsBuilder() | ||
.filter( | ||
Sequelize.where( | ||
Sequelize.fn('isnull', Sequelize.col('Buffet.isDeleted'), 0), | ||
{ | ||
[Op.eq]: 0, | ||
}, | ||
), | ||
) | ||
.build(), | ||
); | ||
|
||
return { | ||
title: 'صورت حساب ها', | ||
menus: JSON.parse(JSON.stringify(menus)), | ||
sitename: req.sitename, | ||
buffets: JSON.parse(JSON.stringify(buffets)), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.