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 post user - admin endpoint #62

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
117 changes: 54 additions & 63 deletions apps/backend/src/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,60 @@
import {
Controller,
Get,
Post,
Body,
Param,
Put,
} from "@nestjs/common";
import { Controller, Get, Post, Body, Param, Put } from '@nestjs/common';
import { ApiParam } from '@nestjs/swagger';
import { UserService } from "./user.service";
import { NewUserInput } from "../dtos/newUserDTO";
import { UserModel, UserStatus, EditUserModel } from "./user.model";

import { UserService } from './user.service';
import { NewUserInput } from '../dtos/newUserDTO';
import { UserModel, UserStatus, EditUserModel, Role } from './user.model';

/**
* The controller for user endpoints.
*/
@Controller("users")
@Controller('users')
export class UserController {
constructor(private userService: UserService) {}

@Get(":id")
public async getUser(
@Param("id") userId?: number
): Promise<UserModel> {
return this.userService.getUser(userId);
}

@Post("/addVolunteer")
public async addVolunteer( @Body() userData: NewUserInput) {
return this.userService.postUserVolunteer(userData);
}

@Get(":id/sites")
public async getUserSites(@Param("id") userId?: number): Promise<any> {
return this.userService.getUserTables(userId);
}


@Put("/editUser/:id")
public async editUser(
@Param("id") userId?: number,
@Body() editUserModel?: EditUserModel
): Promise<UserModel> {
return this.userService.editUser(userId, editUserModel);
}

/**
* Gets users by their status.
* @param status The status to filter users by (e.g., Approved, Pending, Denied).
* @returns A list of users with the specified status.
*/
@Get("status/:status")
@ApiParam({
name: 'status',
description: 'The status to filter users by (e.g., Approved, Pending, Denied)',
enum: UserStatus,
})
public async getUserByStatus(
@Param("status") status: UserStatus
): Promise<UserModel[]> {
console.log(status);
return this.userService.getUserByStatus(status);
}




}
constructor(private userService: UserService) {}

@Get(':id')
public async getUser(@Param('id') userId?: number): Promise<UserModel> {
return this.userService.getUser(userId);
}

@Post('addVolunteer')
public async addVolunteer(@Body() userData: NewUserInput) {
return this.userService.postUser(userData, Role.VOLUNTEER);
}

@Post('addAdmin')
public async addAdmin(@Body() userData: NewUserInput) {
return this.userService.postUser(userData, Role.ADMIN);
}

@Get(':id/sites')
public async getUserSites(@Param('id') userId?: number): Promise<any> {
return this.userService.getUserTables(userId);
}

@Put('/editUser/:id')
public async editUser(
@Param('id') userId?: number,
@Body() editUserModel?: EditUserModel,
): Promise<UserModel> {
return this.userService.editUser(userId, editUserModel);
}

/**
* Gets users by their status.
* @param status The status to filter users by (e.g., Approved, Pending, Denied).
* @returns A list of users with the specified status.
*/
@Get('status/:status')
@ApiParam({
name: 'status',
description:
'The status to filter users by (e.g., Approved, Pending, Denied)',
enum: UserStatus,
})
public async getUserByStatus(
@Param('status') status: UserStatus,
): Promise<UserModel[]> {
console.log(status);
return this.userService.getUserByStatus(status);
}
}
Loading
Loading