Skip to content

Commit

Permalink
add all factor report module
Browse files Browse the repository at this point in the history
  • Loading branch information
bahram1249 committed Mar 12, 2024
1 parent c6cba83 commit 74b8dc0
Show file tree
Hide file tree
Showing 13 changed files with 464 additions and 0 deletions.
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);
}
}
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 {}
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,
};
}
}
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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './all-factor-report.dto';
4 changes: 4 additions & 0 deletions apps/discount-coffe/src/controller/admin/admin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { HolidayModule } from './holiday/holiday.module';
import { HolidayController } from './holiday/holiday.controller';
import { FactorReportModule } from './factor-report/factor-report.module';
import { FactorReportController } from './factor-report/factor-report.controller';
import { AllFactorReportModule } from './all-factor-report/all-factor-report.module';
import { AllFactorReportController } from './all-factor-report/all-factor-report.controller';

@Module({
imports: [
Expand All @@ -33,6 +35,7 @@ import { FactorReportController } from './factor-report/factor-report.controller
QrScanModule,
HolidayModule,
FactorReportModule,
AllFactorReportModule,
],
})
export class AdminModule implements NestModule {
Expand All @@ -50,6 +53,7 @@ export class AdminModule implements NestModule {
QrScanController,
HolidayController,
FactorReportController,
AllFactorReportController,
);
}
}
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);
}
}
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 {}
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)),
};
}
}
2 changes: 2 additions & 0 deletions apps/discount-coffe/src/discountCoffe.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { UserModule } from './controller/user/user.module';
import { AdminModule } from './controller/admin/admin.module';
import { QrScanApiModule } from './api/admin/qrscan/qrscan.module';
import { HolidayApiModule } from './api/admin/holiday/holiday.module';
import { AllFactorReportApiModule } from './api/admin/all-factor-report/all-factor-report.module';

@Module({
imports: [
Expand All @@ -29,6 +30,7 @@ import { HolidayApiModule } from './api/admin/holiday/holiday.module';
QrScanApiModule,
HolidayApiModule,
BuffetUserModule,
AllFactorReportApiModule,
LoginModule,
HomeModule,
UserModule,
Expand Down
126 changes: 126 additions & 0 deletions apps/main/src/sql/core-v1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9149,6 +9149,132 @@ END
GO


-- discount coffe
-- all reports
IF NOT EXISTS ( SELECT 1 FROM Migrations WHERE version = 'CORE-Permissions-Data-v31'
)
AND EXISTS (
SELECT 1 FROM Settings
WHERE ([key] = 'SITE_NAME' AND [value] IN ('DiscountCoffe'))
)
AND EXISTS (
SELECT 1 FROM Settings
WHERE ([key] = 'CUSTOMER_NAME' AND [value] IN ('DiscountCoffe'))
)

BEGIN

DECLARE @roleId int = (SELECT TOP 1 id FROM Roles WHERE static_id = 1)
DECLARE @userId bigint = (SELECT TOP 1 id FROM Users WHERE static_id = 1)

DECLARE @GroupTemp TABLE (
gorupId int
);

DECLARE @groupId int = null;

DECLARE @entityName nvarchar(256) = N'FactorReport'
DECLARE @groupName nvarchar(256) = N'discountcoffe.admin.allfactorreport'
DECLARE @findParentMenu bit = 1;
DECLARE @parentMenuName nvarchar(256) = N'کافه و رستوران'
DECLARE @menuName nvarchar(256) = N'صورت حساب ها'
DECLARE @menuUrl nvarchar(512) = N'/discountcoffe/admin/allFactorReport'

DECLARE @permissionSymbolShowMenu nvarchar(512) = @groupName + '.showmenu';




-- permission groups
INSERT INTO PermissionGroups(permissionGroupName, [visibility], createdAt, updatedAt)
OUTPUT inserted.id INTO @GroupTemp(gorupId)
SELECT @groupName, 1, GETDATE(), GETDATE();

SELECT @groupId = gorupId FROM @GroupTemp


-- permissions


DECLARE @PermissionTemp TABLE (
permissionId int
);




DELETE FROM @PermissionTemp

INSERT INTO Permissions(permissionName ,permissionSymbol, permissionGroupId,createdAt, updatedAt)
OUTPUT inserted.id INTO @PermissionTemp(permissionId)
SELECT 'SHOWMENU_' + @entityName, @permissionSymbolShowMenu, @groupId,GETDATE(), GETDATE()

INSERT INTO RolePermissions(roleId, permissionId, createdAt, updatedAt)
SELECT @roleId, permissionId, GETDATE(), GETDATE()
FROM @PermissionTemp

DECLARE @permissionId int = null
SELECT @permissionId = permissionId FROM @PermissionTemp




DECLARE @parentMenuId int = null



IF @findParentMenu = 0
BEGIN
-- INSERT ParentMenu
DECLARE @ParentMenuTemp TABLE (
menuId int
);

INSERT INTO Menus(title, url, className, visibility, createdAt, updatedAt)
OUTPUT inserted.id INTO @ParentMenuTemp(menuId)
SELECT @parentMenuName, null, null, null, GETDATE(), GETDATE()

SELECT @parentMenuId = menuId FROM @ParentMenuTemp

END
ELSE
BEGIN
SELECT @parentMenuId = id
FROM Menus
WHERE title = @parentMenuName
END

IF @parentMenuId IS NOT NULL
AND NOT EXISTS (SELECT 1 FROM PermissionMenus WHERE permissionId = @permissionId AND menuId = @parentMenuId)
BEGIN
INSERT INTO PermissionMenus(permissionId, menuId, createdAt, updatedAt)
SELECT @permissionId, @parentMenuId, getdate(), getdate()

END

DECLARE @MenuTemp TABLE (
menuId int
);
DECLARE @menuId int = null

INSERT INTO Menus(title, url, parentMenuId, className, visibility, createdAt, updatedAt)
OUTPUT inserted.id INTO @MenuTemp(menuId)
SELECT @menuName, @menuUrl, @parentMenuId,null, null, GETDATE(), GETDATE()

SELECT @menuId = menuId FROM @MenuTemp

INSERT INTO PermissionMenus(permissionId, menuId, createdAt, updatedAt)
SELECT @permissionId, @menuId, getdate(), getdate()



INSERT INTO Migrations(version, createdAt, updatedAt)
SELECT 'CORE-Permissions-Data-v31', GETDATE(), GETDATE()
END

GO


-- period types
IF NOT EXISTS (SELECT 1 FROM Migrations WHERE version = 'PCMPeriodTypes-Data-v1'
)
Expand Down
Loading

0 comments on commit 74b8dc0

Please sign in to comment.