From 7ca8e0dd73dfd2705b27cf4e8a7c9eb76be22800 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 28 Nov 2020 20:39:28 -0600 Subject: [PATCH 01/10] PUT /ticket/{ticket_id} now updates user,ticket,device --- api/src/ticket/ticket.controller.ts | 17 +--- api/src/ticket/ticket.service.ts | 148 +++++++++++++++++++++++++--- 2 files changed, 138 insertions(+), 27 deletions(-) diff --git a/api/src/ticket/ticket.controller.ts b/api/src/ticket/ticket.controller.ts index a93d7f6..9e2f697 100644 --- a/api/src/ticket/ticket.controller.ts +++ b/api/src/ticket/ticket.controller.ts @@ -10,6 +10,7 @@ import { import { ApiTags } from '@nestjs/swagger'; import { CreateCombinedDTO } from './dto/create-combined.dto'; import { TicketType } from './dto/ticket.dto'; +import { UpdateCombinedDTO } from './dto/update-combined.dto'; import { UpdateTicketDto } from './dto/update-ticket.dto'; import { TicketService } from './ticket.service'; @@ -68,20 +69,8 @@ export class TicketController { @Put(':ticket_id') update( @Param('ticket_id') ticket_id: number, - @Body() updateTicketDto: UpdateTicketDto, + @Body() updateCombinedDTO: UpdateCombinedDTO, ) { - Logger.log( - { - req: { - http: `PUT /api/ticket/${ticket_id}`, - params: ticket_id, - body: updateTicketDto, - }, - }, - 'TicketController.update', - false, - ); - - return this.ticketService.update(ticket_id, updateTicketDto); + return this.ticketService.update(ticket_id, updateCombinedDTO); } } diff --git a/api/src/ticket/ticket.service.ts b/api/src/ticket/ticket.service.ts index 332951b..50ca0ff 100644 --- a/api/src/ticket/ticket.service.ts +++ b/api/src/ticket/ticket.service.ts @@ -17,6 +17,10 @@ import { DeviceDTO } from './dto/device.dto'; import { TicketDTO, TicketType } from './dto/ticket.dto'; import { UpdateTicketDto } from './dto/update-ticket.dto'; import { createDate } from 'src/util'; +import { UpdateCombinedDTO } from './dto/update-combined.dto'; +import { UpdateUserDTO } from 'src/user/dto/update-user.dto'; +import { UpdateDeviceDTO } from './dto/update-device.dto'; +import { response } from 'express'; @Injectable() export class TicketService { @@ -160,19 +164,21 @@ export class TicketService { model, operating_system, operating_system_version, + component, } = createDeviceDTO; /* Insert Device into db */ const query: QueryConfig = { name: 'insert_device', text: - 'INSERT INTO device(ticket_id, manufacturer, model, operating_system, operating_system_version) VALUES ($1, $2, $3, $4, $5) RETURNING *', + 'INSERT INTO device(ticket_id, manufacturer, model, operating_system, operating_system_version, component) VALUES ($1, $2, $3, $4, $5 $6) RETURNING *', values: [ ticket_id, manufacturer, model, operating_system, operating_system_version, + component, ], }; try { @@ -400,14 +406,9 @@ export class TicketService { } /* WORKING Implementation */ - async update(ticket_id: number, updateTicketDto: UpdateTicketDto) { - const { - core_issue, - description, - problem_category, - status, - priority, - } = updateTicketDto; + async update(ticket_id: number, updateCombinedDTO: UpdateCombinedDTO) { + let response: CombinedDTO; + let old_lsu_id; /* Check to see if ticket exist */ const findQuery: QueryConfig = { @@ -422,6 +423,7 @@ export class TicketService { if (res.rows.length < 1) { throw new Error('BAD_REQUEST'); } + old_lsu_id = res.rows[0].lsu_id; } catch (error) { /* catch custom error for ticket not found */ if (error.message === 'BAD_REQUEST') { @@ -442,9 +444,66 @@ export class TicketService { HttpStatus.INTERNAL_SERVER_ERROR, ); } + /* Update User */ + const updateUser: UpdateUserDTO = { ...updateCombinedDTO }; + const { + lsu_id, + email, + first_name, + last_name, + department, + phone_number, + } = updateUser; + const updateUserQuery: QueryConfig = { + name: 'update_user', + text: + 'UPDATE "user" SET lsu_id = $1, email = $2, first_name = $3, last_name = $4, department = $5, phone_number = $6 WHERE lsu_id = $7 RETURNING *', + values: [ + lsu_id, + email, + first_name, + last_name, + department, + phone_number, + old_lsu_id, + ], + }; + try { + const res = await this.connection.query(updateUserQuery); + if (res.rows.length < 1) { + throw new Error('BAD_REQUEST'); + } + const user = res.rows[0]; + response = { ...response, ...user }; + } catch (error) { + if (error.message === 'BAD_REQUEST') { + throw new HttpException( + { + query: updateUserQuery, + error: `Update query could not find existing user to update`, + }, + HttpStatus.BAD_REQUEST, + ); + } + throw new HttpException( + { + query: updateUserQuery, + error: error, + }, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } /* Update ticket */ - const updateQuery = { + const updateTicket: UpdateTicketDto = { ...updateCombinedDTO }; + const { + core_issue, + description, + problem_category, + status, + priority, + } = updateTicket; + const updateTicketQuery = { name: 'update_ticket', text: 'UPDATE ticket SET core_issue = $1, description = $2, problem_category = $3, status = $4, priority = $5 WHERE ticket_id = $6 RETURNING *', @@ -458,16 +517,79 @@ export class TicketService { ], }; try { - const res = await this.connection.query(updateQuery); - return res.rows[0]; + const res = await this.connection.query(updateTicketQuery); + if (res.rows.length < 1) { + throw new Error('BAD_REQUEST'); + } + const ticket = res.rows[0]; + response = { ...response, ...ticket }; } catch (error) { + if (error.message === 'BAD_REQUEST') { + throw new HttpException( + { + query: updateUserQuery, + error: `Update query could not find existing user to update`, + }, + HttpStatus.BAD_REQUEST, + ); + } throw new HttpException( { - query: updateQuery, + query: updateTicketQuery, error: error, }, HttpStatus.INTERNAL_SERVER_ERROR, ); } + + /* Update device */ + const updateDevice: UpdateDeviceDTO = { ...updateCombinedDTO }; + const { + manufacturer, + model, + operating_system, + operating_system_version, + component, + } = updateDevice; + const updateDeviceQuery = { + name: 'update_device', + text: + 'UPDATE device SET manufacturer = $1, model = $2, operating_system = $3, operating_system_version = $4, component = $5 WHERE ticket_id = $6 RETURNING *', + values: [ + manufacturer, + model, + operating_system, + operating_system_version, + component, + ticket_id, + ], + }; + try { + const res = await this.connection.query(updateDeviceQuery); + if (res.rows.length < 1) { + throw new Error('BAD_REQUEST'); + } + const device = res.rows[0]; + response = { ...response, ...device }; + } catch (error) { + if (error.message === 'BAD_REQUEST') { + throw new HttpException( + { + query: updateDeviceQuery, + error: `Update query could not find existing device to update`, + }, + HttpStatus.BAD_REQUEST, + ); + } + throw new HttpException( + { + query: updateDeviceQuery, + error: error, + }, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + + return response; } } From 7af81dd03cd17434521f8298b50c0d5b3c4b8a70 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 28 Nov 2020 20:39:54 -0600 Subject: [PATCH 02/10] updated DTOs --- api/src/ticket/dto/update-combined.dto.ts | 14 ++++++++++++++ api/src/ticket/dto/update-device.dto.ts | 4 ++++ 2 files changed, 18 insertions(+) create mode 100644 api/src/ticket/dto/update-combined.dto.ts create mode 100644 api/src/ticket/dto/update-device.dto.ts diff --git a/api/src/ticket/dto/update-combined.dto.ts b/api/src/ticket/dto/update-combined.dto.ts new file mode 100644 index 0000000..c09248b --- /dev/null +++ b/api/src/ticket/dto/update-combined.dto.ts @@ -0,0 +1,14 @@ +import { IntersectionType } from '@nestjs/swagger'; +import { UpdateUserDTO } from 'src/user/dto/update-user.dto'; +import { UpdateDeviceDTO } from './update-device.dto'; +import { UpdateTicketDto } from './update-ticket.dto'; + +class UpdateTicketandDevice extends IntersectionType( + UpdateTicketDto, + UpdateDeviceDTO, +) {} + +export class UpdateCombinedDTO extends IntersectionType( + UpdateTicketandDevice, + UpdateUserDTO, +) {} diff --git a/api/src/ticket/dto/update-device.dto.ts b/api/src/ticket/dto/update-device.dto.ts new file mode 100644 index 0000000..abfd6e5 --- /dev/null +++ b/api/src/ticket/dto/update-device.dto.ts @@ -0,0 +1,4 @@ +import { CreateDeviceDTO } from './create-device.dto'; +import { OmitType as Omit } from '@nestjs/swagger'; + +export class UpdateDeviceDTO extends Omit(CreateDeviceDTO, ['ticket_id']) {} From 3bfb950ce620a3db784c34806a1b229dc86592a0 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 28 Nov 2020 20:40:58 -0600 Subject: [PATCH 03/10] updated endpoints on readme --- api/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/README.md b/api/README.md index c543990..60982be 100644 --- a/api/README.md +++ b/api/README.md @@ -118,12 +118,12 @@ req: none res: body: {CombineDTO} ``` -Updates one ticket by ticket_id; Does NOT update user or device +Updates user, ticket, and device by ticket_id; ``` PUT /api​/ticket​/{ticket_id} -req: body: {UpdateTicketDTO} -res: body: {TicketDTO} +req: body: {UpdateCombinedDTO} +res: body: {CombinedDTO} ``` ## User From bf899390da8ecb992a6a07d809e58c7efdd0b4ec Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 28 Nov 2020 21:36:56 -0600 Subject: [PATCH 04/10] refactored ticketwork -> work --- api/src/app.module.ts | 4 +- api/src/work/dto/create-ticketwork.dto.ts | 18 ------- api/src/work/dto/update-ticketwork.dto.ts | 7 --- api/src/work/entities/ticketwork.entity.ts | 7 --- api/src/work/ticketwork.controller.ts | 44 ---------------- api/src/work/ticketwork.module.ts | 11 ---- api/src/work/ticketwork.service.ts | 58 ---------------------- api/src/work/work.module.ts | 11 ++++ 8 files changed, 13 insertions(+), 147 deletions(-) delete mode 100644 api/src/work/dto/create-ticketwork.dto.ts delete mode 100644 api/src/work/dto/update-ticketwork.dto.ts delete mode 100644 api/src/work/entities/ticketwork.entity.ts delete mode 100644 api/src/work/ticketwork.controller.ts delete mode 100644 api/src/work/ticketwork.module.ts delete mode 100644 api/src/work/ticketwork.service.ts create mode 100644 api/src/work/work.module.ts diff --git a/api/src/app.module.ts b/api/src/app.module.ts index 49dab65..4d6ac3a 100644 --- a/api/src/app.module.ts +++ b/api/src/app.module.ts @@ -4,7 +4,7 @@ import { join } from 'path'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { TicketModule } from './ticket/ticket.module'; -import { TicketWorkModule } from './work/ticketwork.module'; +import { WorkModule } from './work/work.module'; import { AssignmentModule } from './assignment/assignment.module.'; import { UserModule } from './user/uer.module'; @@ -40,7 +40,7 @@ const configImports = (modules: ModuleMetadata['imports']) => { @Module({ imports: configImports([ TicketModule, - TicketWorkModule, + WorkModule, AssignmentModule, UserModule, ]), diff --git a/api/src/work/dto/create-ticketwork.dto.ts b/api/src/work/dto/create-ticketwork.dto.ts deleted file mode 100644 index 1644ef2..0000000 --- a/api/src/work/dto/create-ticketwork.dto.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { ApiProperty } from '@nestjs/swagger'; - -export class CreateTicketWorkDto { - @ApiProperty({ minLength: 3 }) - issue: string; - - @ApiProperty({ minLength: 3 }) - component: string; - - @ApiProperty({}) - description: number; - - @ApiProperty({}) - starttime: Date; - - @ApiProperty({}) - endtime: Date; -} diff --git a/api/src/work/dto/update-ticketwork.dto.ts b/api/src/work/dto/update-ticketwork.dto.ts deleted file mode 100644 index 86d1f9c..0000000 --- a/api/src/work/dto/update-ticketwork.dto.ts +++ /dev/null @@ -1,7 +0,0 @@ -export class UpdateTicketWorkDto { - issue: string; - component: string; - description: string; - starttime: Date; - endtime: Date; -} diff --git a/api/src/work/entities/ticketwork.entity.ts b/api/src/work/entities/ticketwork.entity.ts deleted file mode 100644 index 12679e2..0000000 --- a/api/src/work/entities/ticketwork.entity.ts +++ /dev/null @@ -1,7 +0,0 @@ -export class TicketWork { - issue: string; - component: string; - description: string; - starttime: Date; - endtime: Date; -} diff --git a/api/src/work/ticketwork.controller.ts b/api/src/work/ticketwork.controller.ts deleted file mode 100644 index 814418a..0000000 --- a/api/src/work/ticketwork.controller.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { - Controller, - Get, - Post, - Body, - Put, - Param, - Delete, -} from '@nestjs/common'; -import { TicketWorkService } from './ticketwork.service'; -import { CreateTicketWorkDto } from './dto/create-ticketwork.dto'; -import { UpdateTicketWorkDto } from './dto/update-ticketwork.dto'; -import { ApiTags } from '@nestjs/swagger'; - -@ApiTags('ticket') -@Controller('/api/ticket/work') -export class TicketWorkController { - constructor(private readonly ticketWorkService: TicketWorkService) {} - /* Working Implementation */ - @Post() - async create(@Body() createTicketWorkDto: CreateTicketWorkDto) { - return await this.ticketWorkService.create(createTicketWorkDto); - } - /* TODO */ - @Get() - findAll() { - return this.ticketWorkService.findAll(); - } - /* TODO */ - @Get(':id') - findOne(@Param('id') id: string) { - return this.ticketWorkService.findOne(+id); - } - /* TODO */ - @Put(':id') - update(@Param('id') id: string, @Body() updateTicketWorkDto: UpdateTicketWorkDto) { - return this.ticketWorkService.update(+id, updateTicketWorkDto); - } - /* TODO */ - @Delete(':id') - remove(@Param('id') id: string) { - return this.ticketWorkService.remove(+id); - } -} diff --git a/api/src/work/ticketwork.module.ts b/api/src/work/ticketwork.module.ts deleted file mode 100644 index 8756668..0000000 --- a/api/src/work/ticketwork.module.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Module } from '@nestjs/common'; -import { TicketWorkService } from './ticketwork.service'; -import { TicketWorkController } from './ticketwork.controller'; -import { DbModule } from 'src/db/db.module'; - -@Module({ - imports:[DbModule], - controllers: [TicketWorkController], - providers: [TicketWorkService] -}) -export class TicketWorkModule {} diff --git a/api/src/work/ticketwork.service.ts b/api/src/work/ticketwork.service.ts deleted file mode 100644 index 5d75ba7..0000000 --- a/api/src/work/ticketwork.service.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common'; -import { Pool } from 'pg'; -import { PG_CONNECTION } from 'src/connection'; -import { CreateTicketWorkDto } from './dto/create-ticketwork.dto'; -import { UpdateTicketWorkDto } from './dto/update-ticketwork.dto'; -import { TicketWork } from './entities/ticketwork.entity'; - -/* TODO: - - Implement remaining methods - - Find solution to abstract SQL -*/ -@Injectable() -export class TicketWorkService { - constructor(@Inject(PG_CONNECTION) private connection: Pool) {} - - async create(createTicketWorkDto: CreateTicketWorkDto) { - const { - issue, - component, - description, - starttime, - endtime - } = createTicketWorkDto; - - /* Insert new user into db - TODO: implement error handling for pg request - */ - const text = - 'INSERT INTO ticketwork(issue, component, description, starttime, endtime) VALUES ($1, $2, $3, $4, $5) RETURNING *'; - const values = [issue, component, description, starttime, endtime]; - const res = (await this.connection.query(text, values)).rows[0]; - - /* Return user object without password */ - const ticketwork = new TicketWork(); - ticketwork.issue = res.issue; - ticketwork.component = res.component; - ticketwork.description = res.description; - ticketwork.starttime = res.starttime; - ticketwork.endtime = res.endtime; - return ticketwork; - } - /* TODO */ - findAll() { - return `This action returns all user`; - } - /* TODO */ - findOne(id: number) { - return `This action returns a #${id} user`; - } - /* TODO */ - update(id: number, updateTicketWorkDto: UpdateTicketWorkDto) { - return `This action updates a #${id} user`; - } - /* TODO */ - remove(id: number) { - return `This action removes a #${id} user`; - } -} diff --git a/api/src/work/work.module.ts b/api/src/work/work.module.ts new file mode 100644 index 0000000..518ecc1 --- /dev/null +++ b/api/src/work/work.module.ts @@ -0,0 +1,11 @@ +import { Module } from '@nestjs/common'; +import { WorkService } from './work.service'; +import { WorkController } from './work.controller'; +import { DbModule } from 'src/db/db.module'; + +@Module({ + imports: [DbModule], + controllers: [WorkController], + providers: [WorkService], +}) +export class WorkModule {} From 5bc7d00cffd941c3afe5b590b3f9e5f3d69665b8 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 28 Nov 2020 21:37:10 -0600 Subject: [PATCH 05/10] updated work dtos --- api/src/work/dto/create-work.dto.ts | 4 +++ api/src/work/dto/work.dto.ts | 40 +++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 api/src/work/dto/create-work.dto.ts create mode 100644 api/src/work/dto/work.dto.ts diff --git a/api/src/work/dto/create-work.dto.ts b/api/src/work/dto/create-work.dto.ts new file mode 100644 index 0000000..1b6919e --- /dev/null +++ b/api/src/work/dto/create-work.dto.ts @@ -0,0 +1,4 @@ +import { OmitType as Omit } from '@nestjs/swagger'; +import { WorkDTO } from './work.dto'; + +export class CreateWorkDTO extends Omit(WorkDTO, ['work_id']) {} diff --git a/api/src/work/dto/work.dto.ts b/api/src/work/dto/work.dto.ts new file mode 100644 index 0000000..62540c8 --- /dev/null +++ b/api/src/work/dto/work.dto.ts @@ -0,0 +1,40 @@ +import { ApiProperty } from '@nestjs/swagger'; + +export enum WorkType { + 'LSU_ID', + 'TICKET_ID', +} + +export class WorkDTO { + @ApiProperty({ + readOnly: true, + description: 'serially generated id for work', + }) + work_id: number; + + @ApiProperty({ + description: 'id that references ticket', + example: 1, + }) + ticket_id: number; + + @ApiProperty({ + minLength: 9, + maxLength: 9, + description: '9-digit number starting with 89', + example: 897584512, + }) + lsu_id: number; + + @ApiProperty({ + description: 'YYYY-MM-DD HH:MM:SS', + example: '2020-07-21 12:44:22', + }) + start_datetime: string; + + @ApiProperty({ + description: 'YYYY-MM-DD HH:MM:SS', + example: '2020-07-21 12:44:22', + }) + end_datetime: string; +} From 1a7f30c4f39d973d146d7212367e259fcf8d9e43 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 28 Nov 2020 21:37:25 -0600 Subject: [PATCH 06/10] implemented GET and POST for work --- api/src/work/work.controller.ts | 49 +++++++++++ api/src/work/work.service.ts | 140 ++++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 api/src/work/work.controller.ts create mode 100644 api/src/work/work.service.ts diff --git a/api/src/work/work.controller.ts b/api/src/work/work.controller.ts new file mode 100644 index 0000000..51225a1 --- /dev/null +++ b/api/src/work/work.controller.ts @@ -0,0 +1,49 @@ +import { + Controller, + Get, + Post, + Body, + Put, + Param, + Delete, +} from '@nestjs/common'; +import { WorkService } from './work.service'; +import { CreateWorkDTO } from './dto/create-work.dto'; +import { ApiTags } from '@nestjs/swagger'; +import { WorkType } from './dto/work.dto'; + +@ApiTags('work') +@Controller('/api/work') +export class WorkController { + constructor(private readonly workService: WorkService) {} + + /* Working Implementation */ + @Post() + async create(@Body() createWorkDTO: CreateWorkDTO) { + return await this.workService.create(createWorkDTO); + } + + /* Working Implementation */ + @Get() + findAll() { + return this.workService.findAll(); + } + + /* Working Implementation */ + @Get('ticket/:ticket_id') + findAllByTicketId(@Param('ticket_id') ticket_id: number) { + return this.workService.findAllById(WorkType.TICKET_ID, ticket_id); + } + + /* Working Implementation */ + @Get('user/:lsu_id') + findAllByLsuId(@Param('lsu_id') lsu_id: number) { + return this.workService.findAllById(WorkType.LSU_ID, lsu_id); + } + + /* Working Implementation */ + @Get(':work_id') + findOne(@Param('work_id') id: number) { + return this.workService.findOne(+id); + } +} diff --git a/api/src/work/work.service.ts b/api/src/work/work.service.ts new file mode 100644 index 0000000..7b504d8 --- /dev/null +++ b/api/src/work/work.service.ts @@ -0,0 +1,140 @@ +import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common'; +import { Pool, QueryConfig } from 'pg'; +import { PG_CONNECTION } from 'src/connection'; +import { CreateWorkDTO } from './dto/create-work.dto'; +import { WorkDTO, WorkType } from './dto/work.dto'; + +/* TODO: + - Implement remaining methods + - Find solution to abstract SQL +*/ +@Injectable() +export class WorkService { + constructor(@Inject(PG_CONNECTION) private connection: Pool) {} + + async create(createTicketWorkDto: CreateWorkDTO) { + const { + lsu_id, + ticket_id, + start_datetime, + end_datetime, + } = createTicketWorkDto; + + /*Insert work into db*/ + const query: QueryConfig = { + name: 'insert_work', + text: + 'INSERT INTO work(lsu_id, ticket_id, start_datetime, end_datetime) VALUES ($1, $2, $3, $4) RETURNING *', + values: [lsu_id, ticket_id, start_datetime, end_datetime], + }; + try { + const res = await this.connection.query(query); + return res.rows[0]; + } catch (error) { + throw new HttpException( + { + query: query, + error: error, + }, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + } + + /* TODO */ + async findAll() { + const query: QueryConfig = { + name: 'find_all_work', + text: 'SELECT * FROM work', + }; + try { + const res = await this.connection.query(query); + if (res.rows.length < 1) { + return []; + } + return res.rows; + } catch (error) { + throw new HttpException( + { + query: query, + error: error, + }, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + } + + /* TODO */ + async findOne(work_id: number) { + const query: QueryConfig = { + name: 'find_work_by_work_id', + text: 'SELECT * FROM work WHERE work_id = $1', + values: [work_id], + }; + try { + const res = await this.connection.query(query); + if (res.rows.length < 1) { + throw new Error('BAD_REQUEST'); + } + return res.rows[0]; + } catch (error) { + if (error.message === 'BAD_REQUEST') { + throw new HttpException( + { + query: query, + error: `No work exists with work_id: ${query.values[0]}`, + }, + HttpStatus.BAD_REQUEST, + ); + } + throw new HttpException( + { + query: query, + error: error, + }, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + } + async findAllById(type: WorkType, id: number) { + let query: QueryConfig; + switch (type) { + case WorkType.LSU_ID: + query = { + name: 'find_all_work_by_lsu_id', + text: 'SELECT * from work WHERE lsu_id = $1', + values: [id], + }; + break; + case WorkType.TICKET_ID: + query = { + name: 'find_all_work_by_ticket_id', + text: 'SELECT * from work WHERE ticket_id = $1', + values: [id], + }; + break; + default: + throw new HttpException( + { + error: 'Switch statement in work.service.findAllById failed', + }, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + try { + const res = await this.connection.query(query); + if (res.rows.length < 1) { + return []; + } + return res.rows; + } catch (error) { + throw new HttpException( + { + query: query, + error: error, + }, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + } +} From e7fd6a8e7f7a4ab4b2685c289cb76181a454a113 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 28 Nov 2020 21:43:40 -0600 Subject: [PATCH 07/10] updated endpoints to readme --- api/README.md | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/api/README.md b/api/README.md index 60982be..07b3655 100644 --- a/api/README.md +++ b/api/README.md @@ -140,6 +140,7 @@ Get all users ``` GET /api​/user +req: none res: body: {UserDTO[]} ``` @@ -147,6 +148,7 @@ Get all users who are admins ``` GET /api​/user/admin +req: none res: body: {UserDTO[]} ``` @@ -154,6 +156,7 @@ Get all users who are not admins ``` GET /api​/user/student +req: none res: body: {UserDTO[]} ``` @@ -161,6 +164,7 @@ Get user by lsu_id ``` GET /api​/user/{lsu_id} +req: none res: body: {UserDTO} ``` @@ -178,6 +182,7 @@ Get all assignments ``` GET /api/assignment +req: none res: body: {AssignmentDTO} ``` @@ -185,6 +190,7 @@ Get all assignments assigned to admin by lsu_id ``` GET /api/assignment/user/{lsu_id} +req: none res: body: {AssignmentDTO[]} ``` @@ -192,6 +198,7 @@ Get all assignments assigned to ticket by ticket_id ``` GET /api/assignment/ticket/{ticket_id} +req: none res: body: {AssignmentDTO[]} ``` @@ -199,6 +206,7 @@ Get one assignment by assignment_id ``` GET /api/assignment/{assignment_id} +req: none res: body: {AssignmentDTO} ``` @@ -212,4 +220,42 @@ res: body: {AssignmentDTO} ## Work -TODO +Get all work + +``` +GET /api/work +req: none +res: body: {WorkDTO[]} +``` + +Get all work by ticket_id + +``` +GET /api/work/ticket/{ticket_id} +req: none +res: body: {WorkDTO[]} +``` + +Get all work by lsu_id + +``` +GET /api/work/user/{lsu_id} +req: none +res: body: {WorkDTO[]} +``` + +Get work by work_id + +``` +GET /api/work/{work_id} +req: none +res: body: {WorkDTO} +``` + +Post new work + +``` +POST /api/work +req: body: {CreateWorkDTO} +res: body: {WorkDTO} +``` From b03a0dbf2275d530cc481ca8dd75b1e3511fafbc Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 28 Nov 2020 21:43:48 -0600 Subject: [PATCH 08/10] updated imporsts --- api/src/work/work.controller.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/api/src/work/work.controller.ts b/api/src/work/work.controller.ts index 51225a1..8ee2c93 100644 --- a/api/src/work/work.controller.ts +++ b/api/src/work/work.controller.ts @@ -1,16 +1,8 @@ -import { - Controller, - Get, - Post, - Body, - Put, - Param, - Delete, -} from '@nestjs/common'; -import { WorkService } from './work.service'; -import { CreateWorkDTO } from './dto/create-work.dto'; +import { Body, Controller, Get, Param, Post } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; +import { CreateWorkDTO } from './dto/create-work.dto'; import { WorkType } from './dto/work.dto'; +import { WorkService } from './work.service'; @ApiTags('work') @Controller('/api/work') From 74231e79bb597c9aa3216abbc9112a09eb6743ce Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 28 Nov 2020 21:53:20 -0600 Subject: [PATCH 09/10] updated fields notes on ticket and component on device --- api/src/ticket/dto/create-ticket.dto.ts | 1 + api/src/ticket/dto/device.dto.ts | 3 ++- api/src/ticket/dto/ticket.dto.ts | 10 +++++++++- api/src/ticket/ticket.service.ts | 4 +++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/api/src/ticket/dto/create-ticket.dto.ts b/api/src/ticket/dto/create-ticket.dto.ts index a8adb5f..506c558 100644 --- a/api/src/ticket/dto/create-ticket.dto.ts +++ b/api/src/ticket/dto/create-ticket.dto.ts @@ -5,4 +5,5 @@ export class CreateTicketDTO extends Omit(TicketDTO, [ 'ticket_id', 'status', 'submission_date', + 'notes', ]) {} diff --git a/api/src/ticket/dto/device.dto.ts b/api/src/ticket/dto/device.dto.ts index 022de62..6d0c3d7 100644 --- a/api/src/ticket/dto/device.dto.ts +++ b/api/src/ticket/dto/device.dto.ts @@ -18,8 +18,9 @@ export class DeviceDTO { description: 'physical hardware part that is damaged', example: 'screen', nullable: true, + default: null, }) - component: string; + component: string | null; @ApiProperty({ description: 'manufacturer of device', example: 'dell' }) manufacturer: string; diff --git a/api/src/ticket/dto/ticket.dto.ts b/api/src/ticket/dto/ticket.dto.ts index 2048e6c..f2844a9 100644 --- a/api/src/ticket/dto/ticket.dto.ts +++ b/api/src/ticket/dto/ticket.dto.ts @@ -38,7 +38,6 @@ export class TicketDTO { }) description: string; - // Not sure of difference between description and problem @ApiProperty({ description: 'label of problem student is facing', example: 'computer slowdown', @@ -50,4 +49,13 @@ export class TicketDTO { example: '2020-07-21 12:44:22', }) submission_date: string; + + @ApiProperty({ + description: 'notes for admin to add', + example: 'TODO: some note', + maxLength: 500, + default: null, + nullable: true, + }) + notes: string | null; } diff --git a/api/src/ticket/ticket.service.ts b/api/src/ticket/ticket.service.ts index 50ca0ff..12e9304 100644 --- a/api/src/ticket/ticket.service.ts +++ b/api/src/ticket/ticket.service.ts @@ -502,17 +502,19 @@ export class TicketService { problem_category, status, priority, + notes, } = updateTicket; const updateTicketQuery = { name: 'update_ticket', text: - 'UPDATE ticket SET core_issue = $1, description = $2, problem_category = $3, status = $4, priority = $5 WHERE ticket_id = $6 RETURNING *', + 'UPDATE ticket SET core_issue = $1, description = $2, problem_category = $3, status = $4, priority = $5, notes = $6 WHERE ticket_id = $7 RETURNING *', values: [ core_issue, description, problem_category, status, priority, + notes, ticket_id, ], }; From 05139ad9e5291b232279290db8b907487eaf4243 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 28 Nov 2020 21:53:50 -0600 Subject: [PATCH 10/10] updated imports --- api/src/ticket/dto/update-ticket.dto.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/api/src/ticket/dto/update-ticket.dto.ts b/api/src/ticket/dto/update-ticket.dto.ts index 0da1bdd..fdb46b4 100644 --- a/api/src/ticket/dto/update-ticket.dto.ts +++ b/api/src/ticket/dto/update-ticket.dto.ts @@ -1,7 +1,5 @@ -import { PartialType } from '@nestjs/swagger'; -import { CreateTicketDTO } from './create-ticket.dto'; -import { TicketDTO } from './ticket.dto'; import { OmitType as Omit } from '@nestjs/swagger'; +import { TicketDTO } from './ticket.dto'; export class UpdateTicketDto extends Omit(TicketDTO, [ 'ticket_id',