Skip to content
Draft
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
3 changes: 2 additions & 1 deletion apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { AuthModule } from "./aws/auth.module";

import { AuthenticationMiddleware } from "./aws/middleware/authentication.middleware";
import { UserModule } from "./users/users.module";
import { TimesheetModule } from "./timesheet/timesheet.module";

@Module({
imports: [AuthModule, UserModule],
imports: [AuthModule, UserModule, TimesheetModule],
controllers: [AppController],
providers: [AppService],
})
Expand Down
57 changes: 0 additions & 57 deletions apps/backend/src/aws/auth.controller.ts

This file was deleted.

3 changes: 1 addition & 2 deletions apps/backend/src/aws/auth.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Module } from "@nestjs/common";

import { AuthService } from "./auth.service";
import { AuthController } from "./auth.controller";
import { CognitoService } from "./cognito/cognito.service";
import { CognitoWrapper } from "./cognito/cognito.wrapper";

@Module({
imports: [],
providers: [AuthService, CognitoService, CognitoWrapper],
controllers: [AuthController],
controllers: [],
exports: [AuthService],
})
export class AuthModule {}
59 changes: 59 additions & 0 deletions apps/backend/src/timesheet/timesheet.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {
Controller,
Get,
Post,
Headers,
Body,
UseGuards,
HttpStatus,
HttpException,
} from "@nestjs/common";
import * as frontendTimesheetSchemas from 'src/db/schemas/Timesheet'
import { RolesGuard } from 'src/utils/guards/roles.guard';
import { UploadTimesheet } from 'src/db/timesheets/UploadTimesheet';
import { Formatter } from 'src/db/timesheets/Formatter';
import { ValidatedUser } from "src/aws/auth.service";
import { User } from "src/utils/decorators/user.decorator";


@Controller("timesheet")
@UseGuards(RolesGuard)
export class TimesheetController {
uploadApi = new UploadTimesheet();

@Post('update')
public async updateTimesheet(
@Headers() headers: any,
@User() user: ValidatedUser,
@Body() body: any
): Promise<string> {
if (!user.sub) {
throw new HttpException(
"No authorized user found",
HttpStatus.UNAUTHORIZED
);
}

console.log("Update Timesheet Request: Processing")
console.log("Request received:")
console.log(body)
const result = this.uploadApi.updateTimesheet(body, user.sub);

//TODO: Do something with this result?
return result;
}

@Get("")
public async grabTimesheets(@Headers() headers: any,
@User() user: ValidatedUser,
): Promise<frontendTimesheetSchemas.TimeSheetSchema[]> {
if (!user.sub) {
throw new HttpException(
"No authorized user found",
HttpStatus.UNAUTHORIZED
);
}

return Formatter.fetchUserTimesheets(user.sub);
}
}
12 changes: 12 additions & 0 deletions apps/backend/src/timesheet/timesheet.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from "@nestjs/common";
import { TimesheetController } from "./timesheet.controller";
import { TimesheetService } from "./timesheet.service";


@Module({
imports: [],
providers: [TimesheetService],
controllers: [TimesheetController],
exports: [],
})
export class TimesheetModule { }
9 changes: 9 additions & 0 deletions apps/backend/src/timesheet/timesheet.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {
Injectable,
} from "@nestjs/common";


@Injectable()
export class TimesheetService {
constructor() {}
}