Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add group from table number #10

Merged
merged 2 commits into from
Nov 2, 2024
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
69 changes: 50 additions & 19 deletions apps/backend-bff/src/app/remoteGroup/remote.group.controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import { Body, Controller, Delete, Get, HttpCode, HttpException, HttpStatus, Param, Post } from '@nestjs/common';
import { GroupNotFoundException, NoGroupsFoundException } from '@spos/services/common';

import {
Body,
Controller,
Delete,
Get,
HttpCode,
HttpException,
HttpStatus,
Param,
Post,
} from '@nestjs/common';
import {
container,
Group,
GroupCreateDto, GroupService,
GroupCreateDto,
GroupNotFoundException,
GroupService,
GroupServiceWorkflow,
NoGroupsFoundException,
Table,
TableCreateDto, TYPES
} from "@spos/services/common";
TableCreateDto,
TYPES,
} from '@spos/services/common';
import { ApiProperty, ApiTags } from '@nestjs/swagger';

export class TableDto implements Table {
Expand All @@ -20,9 +32,10 @@ export class TableDto implements Table {
@ApiProperty()
customerCount: number;
}
export class Status{

export class Status {
@ApiProperty()
success : boolean;
success: boolean;
}

export class AnnotatedGroup implements Group {
Expand Down Expand Up @@ -73,10 +86,8 @@ export class RemoteGroupController {
}

@Delete(':id')
async removeGroup(
@Param('id') id: string
) : Promise<Status> {
try{
async removeGroup(@Param('id') id: string): Promise<Status> {
try {
await container.get<GroupService>(TYPES.GroupService).removeGroup(id);
return { success: true };
} catch (error) {
Expand All @@ -86,30 +97,50 @@ export class RemoteGroupController {
status: HttpStatus.NOT_FOUND,
error: `Group with id ${id} doesn't exist!`,
},
HttpStatus.NOT_FOUND,
HttpStatus.NOT_FOUND
);
}
}

}

@Delete()
async removeAllGroups(): Promise<Status> {
try{
try {
await container.get<GroupService>(TYPES.GroupService).removeAllGroups();
return { success: true };
}catch (error) {
} catch (error) {
if (error instanceof NoGroupsFoundException) {
throw new HttpException(
{
status: HttpStatus.NOT_FOUND,
error: `Groups doesn't exist!`,
},
HttpStatus.NOT_FOUND,
HttpStatus.NOT_FOUND
);
}
}

}


@Get('groupFromTableNumber/:tableNumber')
async getGroupFromTableNumber(
@Param('tableNumber') tableNumber: string
): Promise<AnnotatedGroup> {
let data = null;
try {
data = await container
.get<GroupServiceWorkflow>(TYPES.GroupService)
.getGroupFromTableNumber(tableNumber);
} catch (e) {
if (e instanceof GroupNotFoundException) {
throw new HttpException(
{
status: HttpStatus.NOT_FOUND,
error: `Group with table number ${tableNumber} doesn't exist!`,
},
HttpStatus.NOT_FOUND
);
}
}
return data;
}
}
2 changes: 1 addition & 1 deletion libs/clients/bff/openapi.json

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions libs/clients/bff/src/api/remote-group-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,39 @@ export const RemoteGroupApiAxiosParamCreator = function (configuration?: Configu



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @param {string} tableNumber
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
remoteGroupControllerGetGroupFromTableNumber: async (tableNumber: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'tableNumber' is not null or undefined
assertParamExists('remoteGroupControllerGetGroupFromTableNumber', 'tableNumber', tableNumber)
const localVarPath = `/api/remoteGroup/groupFromTableNumber/{tableNumber}`
.replace(`{${"tableNumber"}}`, encodeURIComponent(String(tableNumber)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
Expand Down Expand Up @@ -226,6 +259,18 @@ export const RemoteGroupApiFp = function(configuration?: Configuration) {
const localVarOperationServerBasePath = operationServerMap['RemoteGroupApi.remoteGroupControllerGetGroup']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
*
* @param {string} tableNumber
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async remoteGroupControllerGetGroupFromTableNumber(tableNumber: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<AnnotatedGroup>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.remoteGroupControllerGetGroupFromTableNumber(tableNumber, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['RemoteGroupApi.remoteGroupControllerGetGroupFromTableNumber']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
*
* @param {*} [options] Override http request option.
Expand Down Expand Up @@ -288,6 +333,15 @@ export const RemoteGroupApiFactory = function (configuration?: Configuration, ba
remoteGroupControllerGetGroup(requestParameters: RemoteGroupApiRemoteGroupControllerGetGroupRequest, options?: RawAxiosRequestConfig): AxiosPromise<AnnotatedGroup> {
return localVarFp.remoteGroupControllerGetGroup(requestParameters.id, options).then((request) => request(axios, basePath));
},
/**
*
* @param {RemoteGroupApiRemoteGroupControllerGetGroupFromTableNumberRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
remoteGroupControllerGetGroupFromTableNumber(requestParameters: RemoteGroupApiRemoteGroupControllerGetGroupFromTableNumberRequest, options?: RawAxiosRequestConfig): AxiosPromise<AnnotatedGroup> {
return localVarFp.remoteGroupControllerGetGroupFromTableNumber(requestParameters.tableNumber, options).then((request) => request(axios, basePath));
},
/**
*
* @param {*} [options] Override http request option.
Expand Down Expand Up @@ -344,6 +398,20 @@ export interface RemoteGroupApiRemoteGroupControllerGetGroupRequest {
readonly id: string
}

/**
* Request parameters for remoteGroupControllerGetGroupFromTableNumber operation in RemoteGroupApi.
* @export
* @interface RemoteGroupApiRemoteGroupControllerGetGroupFromTableNumberRequest
*/
export interface RemoteGroupApiRemoteGroupControllerGetGroupFromTableNumberRequest {
/**
*
* @type {string}
* @memberof RemoteGroupApiRemoteGroupControllerGetGroupFromTableNumber
*/
readonly tableNumber: string
}

/**
* Request parameters for remoteGroupControllerRemoveGroup operation in RemoteGroupApi.
* @export
Expand Down Expand Up @@ -387,6 +455,17 @@ export class RemoteGroupApi extends BaseAPI {
return RemoteGroupApiFp(this.configuration).remoteGroupControllerGetGroup(requestParameters.id, options).then((request) => request(this.axios, this.basePath));
}

/**
*
* @param {RemoteGroupApiRemoteGroupControllerGetGroupFromTableNumberRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof RemoteGroupApi
*/
public remoteGroupControllerGetGroupFromTableNumber(requestParameters: RemoteGroupApiRemoteGroupControllerGetGroupFromTableNumberRequest, options?: RawAxiosRequestConfig) {
return RemoteGroupApiFp(this.configuration).remoteGroupControllerGetGroupFromTableNumber(requestParameters.tableNumber, options).then((request) => request(this.axios, this.basePath));
}

/**
*
* @param {*} [options] Override http request option.
Expand Down
5 changes: 5 additions & 0 deletions libs/services/common/src/lib/group/groupRemoteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@ export class GroupRemoteService implements GroupService {

return (await this.backendBffApiService.getRemoteGroupApi().remoteGroupControllerRemoveAllGroups()).data.success;
}
@perf()
@logger
async getGroupFromTableNumber(tableNumber: string) {
return (await this.backendBffApiService.getRemoteGroupApi().remoteGroupControllerGetGroupFromTableNumber({tableNumber})).data;
}

}
6 changes: 4 additions & 2 deletions libs/services/common/src/lib/group/groupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export interface GroupService {

getGroups(): Promise<Group[]>;

removeGroup(id : string) : Promise<boolean>;
removeGroup(id: string): Promise<boolean>;

removeAllGroups() : Promise<boolean>;
removeAllGroups(): Promise<boolean>;

getGroupFromTableNumber(tableNumber: string) : Promise<Group>;
}
18 changes: 18 additions & 0 deletions libs/services/common/src/lib/group/groupServiceWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class GroupServiceWorkflow implements GroupService {
this.group[id].tables.sort((a, b) => a.number - b.number);
return this.group[id];
}

@perf()
@logger
async getGroup(id: string) {
Expand All @@ -51,11 +52,13 @@ export class GroupServiceWorkflow implements GroupService {
}
return this.group[id];
}

@perf()
@logger
async getGroups() {
return Object.values(this.group);
}

@perf()
@logger
async removeGroup(id: string): Promise<boolean> {
Expand All @@ -69,6 +72,7 @@ export class GroupServiceWorkflow implements GroupService {
throw new GroupNotFoundException(`Group with id ${id} not found.`);
}
}

@perf()
@logger
async removeAllGroups(): Promise<boolean> {
Expand All @@ -82,4 +86,18 @@ export class GroupServiceWorkflow implements GroupService {
}
return true;
}

@logger
async getGroupFromTableNumber(tableNumber: string) {
for (const group of Object.values(this.group)) {
for (const table of group.tables) {
if (table.number.toString() === tableNumber) {
return group;
}
}
}
throw new GroupNotFoundException(
`Group with table number ${tableNumber} not found.`
);
}
}
Loading