Skip to content

Commit

Permalink
Merge pull request #15 from cdalton713/backend
Browse files Browse the repository at this point in the history
Backend: implemented Update User and Update Ticket
  • Loading branch information
alxford45 authored Nov 28, 2020
2 parents 47c5fec + 84db8b7 commit a4272fd
Show file tree
Hide file tree
Showing 16 changed files with 297 additions and 123 deletions.
12 changes: 7 additions & 5 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ req: none
res: body: {CombineDTO}
```

Update ticket
Updates one ticket by ticket_id; Does NOT update user or device

```
/* NOT WORKING */
PUT /api​/ticket​/{id}
PUT /api​/ticket​/{ticket_id}
req: body: {UpdateTicketDTO}
res: body: {TicketDTO}
```

## User
Expand Down Expand Up @@ -155,11 +156,12 @@ GET /api​/user/{lsu_id}
res: body: {UserDTO}
```

Update user
Update user by lsu_id

```
/* NOT WORKING */
PUT /api/user/{lsu_id}
req: body: {UpdateUserDTO}
res: body: {UserDTO}
```

## Assign
Expand Down
2 changes: 1 addition & 1 deletion api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function bootstrap() {
.setVersion('0.1.0')
.setExternalDoc(
'additional documentation',
`http://${HOST}:${PORT}/api/docs/more`,
`https://github.com/cdalton713/CSC_4402_DB_Project/blob/master/api/README.md`,
)
.build();
const document = SwaggerModule.createDocument(app, options);
Expand Down
13 changes: 8 additions & 5 deletions api/src/ticket/dto/combined.dto.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { IntersectionType } from '@nestjs/swagger';
import { Ticket } from './ticket.dto';
import { User } from 'src/user/dto/user.dto';
import { Device } from './device.dto';
import { TicketDTO } from './ticket.dto';
import { UserDTO } from 'src/user/dto/user.dto';
import { DeviceDTO } from './device.dto';

class TicketAndDevice extends IntersectionType(Ticket, Device) {}
class TicketAndDeviceDTO extends IntersectionType(TicketDTO, DeviceDTO) {}

export class Combined extends IntersectionType(TicketAndDevice, User) {}
export class CombinedDTO extends IntersectionType(
TicketAndDeviceDTO,
UserDTO,
) {}
18 changes: 9 additions & 9 deletions api/src/ticket/dto/create-combined.dto.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { IntersectionType, OmitType as Omit } from '@nestjs/swagger';
import { CreateUser } from 'src/user/dto/create-user.dto';
import { CreateTicket } from './create-ticket.dto';
import { CreateDevice } from './create-device.dto';
import { CreateUserDTO } from 'src/user/dto/create-user.dto';
import { CreateTicketDTO } from './create-ticket.dto';
import { CreateDeviceDTO } from './create-device.dto';

class createTicketAndDevice extends IntersectionType(
CreateTicket,
Omit(CreateDevice, ['ticket_id']),
class createTicketAndDeviceDTO extends IntersectionType(
CreateTicketDTO,
Omit(CreateDeviceDTO, ['ticket_id']),
) {}

export class CreateCombined extends IntersectionType(
createTicketAndDevice,
Omit(CreateUser, ['admin']),
export class CreateCombinedDTO extends IntersectionType(
createTicketAndDeviceDTO,
Omit(CreateUserDTO, ['admin']),
) {}
4 changes: 2 additions & 2 deletions api/src/ticket/dto/create-device.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OmitType as Omit } from '@nestjs/swagger';
import { Device } from './device.dto';
import { DeviceDTO } from './device.dto';

export class CreateDevice extends Omit(Device, ['device_id']) {}
export class CreateDeviceDTO extends Omit(DeviceDTO, ['device_id']) {}
8 changes: 6 additions & 2 deletions api/src/ticket/dto/create-ticket.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Ticket } from './ticket.dto';
import { TicketDTO } from './ticket.dto';
import { OmitType as Omit } from '@nestjs/swagger';

export class CreateTicket extends Omit(Ticket, ['ticket_id', 'status']) {}
export class CreateTicketDTO extends Omit(TicketDTO, [
'ticket_id',
'status',
'submission_date',
]) {}
2 changes: 1 addition & 1 deletion api/src/ticket/dto/device.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';

export class Device {
export class DeviceDTO {
@ApiProperty({ description: 'id of device', example: 1 })
device_id: number;

Expand Down
2 changes: 1 addition & 1 deletion api/src/ticket/dto/ticket.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export enum TicketType {
'ANY',
}

export class Ticket {
export class TicketDTO {
@ApiProperty({ readOnly: true })
ticket_id: number;

Expand Down
10 changes: 8 additions & 2 deletions api/src/ticket/dto/update-ticket.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { PartialType } from '@nestjs/swagger';
import { Ticket } from './ticket.dto';
import { CreateTicketDTO } from './create-ticket.dto';
import { TicketDTO } from './ticket.dto';
import { OmitType as Omit } from '@nestjs/swagger';

export class UpdateTicketDto extends PartialType(Ticket) {}
export class UpdateTicketDto extends Omit(TicketDTO, [
'ticket_id',
'submission_date',
'lsu_id',
]) {}
36 changes: 19 additions & 17 deletions api/src/ticket/ticket.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Put,
} from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { CreateCombined } from './dto/create-combined.dto';
import { CreateCombinedDTO } from './dto/create-combined.dto';
import { TicketType } from './dto/ticket.dto';
import { UpdateTicketDto } from './dto/update-ticket.dto';
import { TicketService } from './ticket.service';
Expand All @@ -18,68 +18,70 @@ import { TicketService } from './ticket.service';
export class TicketController {
constructor(private readonly ticketService: TicketService) {}

/* TODO: test implementation */
/* WORKING Implementation */
@Post()
create(@Body() createCombined: CreateCombined) {
create(@Body() createCombinedDTO: CreateCombinedDTO) {
Logger.log(
{
req: {
http: 'POST /api/ticket',
params: 'none',
body: createCombined,
body: createCombinedDTO,
},
},
'TicketController.create',
false,
);
return this.ticketService.create(createCombined);
return this.ticketService.create(createCombinedDTO);
}

/* Working implementation */
/* WORKING Implementation */
@Get()
findAll() {
return this.ticketService.findAll(TicketType.ANY);
}
/* Working implementation */
/* WORKING Implementation */
@Get('/opened')
findAllOpened() {
return this.ticketService.findAll(TicketType.OPENED);
}

/* Working implementation */
/* WORKING Implementation */
@Get('/closed')
findAllClosed() {
return this.ticketService.findAll(TicketType.CLOSED);
}

/* Working implementation */
/* WORKING Implementation */
@Get('/user/:lsu_id')
findAllByLsuId(@Param('lsu_id') lsu_id: number) {
return this.ticketService.findAll(lsu_id);
}

/* Working implementation */
/* WORKING Implementation */
@Get(':ticket_id')
findOne(@Param('ticket_id') ticket_id: number) {
return this.ticketService.findOne(+ticket_id);
}

/* TODO: FIX */
/* NOT WORKING */
@Put(':id')
update(@Param('id') id: number, @Body() updateTicketDto: UpdateTicketDto) {
/* WORKING Implementation */
@Put(':ticket_id')
update(
@Param('ticket_id') ticket_id: number,
@Body() updateTicketDto: UpdateTicketDto,
) {
Logger.log(
{
req: {
http: `PUT /api/ticket/${id}`,
params: id,
http: `PUT /api/ticket/${ticket_id}`,
params: ticket_id,
body: updateTicketDto,
},
},
'TicketController.update',
false,
);

return this.ticketService.update(id, updateTicketDto);
return this.ticketService.update(ticket_id, updateTicketDto);
}
}
Loading

0 comments on commit a4272fd

Please sign in to comment.