Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chromium-52 committed Oct 30, 2023
2 parents b685272 + c57daba commit 8c5fa6f
Show file tree
Hide file tree
Showing 12 changed files with 348 additions and 32 deletions.
22 changes: 22 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### ℹ️ Issue

Closes <issue>

### 📝 Description

Write a short summary of what you added. Why is it important? Any member of C4C should be able to read this and understand your contribution -- not just your team members.

Briefly list the changes made to the code:
1. Added support for this.
2. And removed redunant use of that.
3. Also this was included for reasons.

### ✔️ Verification

What steps did you take to verify your changes work? These should be clear enough for someone to be able to clone the branch and follow the steps themselves.

Provide screenshots of any new components, styling changes, or pages.

### 🏕️ (Optional) Future Work / Notes

Did you notice anything ugly during the course of this ticket? Any bugs, design challenges, or unexpected behavior? Write it down so we can clean it up in a future ticket!
56 changes: 28 additions & 28 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,37 +77,37 @@ jobs:
deploy-frontend:
needs: pre-deploy
if: (contains(github.event.inputs.manual-deploy, 'scaffolding-frontend') || contains(needs.pre-deploy.outputs.affected, 'scaffolding-frontend')) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main'
if: (contains(github.event.inputs.manual-deploy, 'c4c-ops-frontend') || contains(needs.pre-deploy.outputs.affected, 'scaffolding-frontend')) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
# For "simplicity", deployment settings are configured in the AWS Amplify Console
# This just posts to a webhook telling Amplify to redeploy the main branch
steps:
- name: Tell Amplify to rebuild
run: curl -X POST -d {} ${SCAFFOLDING_WEBHOOK_DEPLOY} -H "Content-Type:application/json"
run: curl -X POST -d {} ${C4C_OPS_WEBHOOK_DEPLOY} -H "Content-Type:application/json"
env:
SCAFFOLDING_WEBHOOK_DEPLOY: ${{ secrets.SCAFFOLDING_WEBHOOK_DEPLOY }}

# deploy-backend:
# needs: pre-deploy
# if: (contains(github.event.inputs.manual-deploy, 'scaffolding-backend') || contains(needs.pre-deploy.outputs.affected, 'scaffolding-backend')) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main'
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Use Node.js 16
# uses: actions/setup-node@v3
# with:
# node-version: 16.x
# cache: 'yarn'

# - name: Install Dependencies
# run: yarn install

# - run: npx nx build scaffolding-backend --configuration production
# - name: default deploy
# uses: appleboy/lambda-action@master
# with:
# aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws_region: ${{ secrets.AWS_REGION }}
# function_name: scaffolding-monolith-lambda
# source: dist/apps/scaffolding/scaffolding-backend/main.js
C4C_OPS_WEBHOOK_DEPLOY: ${{ secrets.C4C_OPS_WEBHOOK_DEPLOY }}

deploy-backend:
needs: pre-deploy
if: (contains(github.event.inputs.manual-deploy, 'c4c-ops-backend') || contains(needs.pre-deploy.outputs.affected, 'scaffolding-backend')) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'yarn'

- name: Install Dependencies
run: yarn install

- run: npx nx build c4c-ops-backend --configuration production
- name: default deploy
uses: appleboy/lambda-action@master
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_region: ${{ secrets.AWS_REGION }}
function_name: c4c-ops-monolith-lambda
source: dist/apps/c4c-ops/c4c-ops-backend/main.js
4 changes: 3 additions & 1 deletion apps/backend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UsersModule } from '../users/users.module';
import { PluralNamingStrategy } from '../strategies/plural-naming.strategy';

@Module({
Expand All @@ -11,7 +12,7 @@ import { PluralNamingStrategy } from '../strategies/plural-naming.strategy';
type: 'mongodb',
host: '127.0.0.1',
port: 27017,
database: 'scaffoldingTest',
database: 'c4cOpsTest',
// username: 'root',
// password: 'root',
autoLoadEntities: true,
Expand All @@ -20,6 +21,7 @@ import { PluralNamingStrategy } from '../strategies/plural-naming.strategy';
synchronize: true,
namingStrategy: new PluralNamingStrategy(),
}),
UsersModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
7 changes: 6 additions & 1 deletion apps/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This is only a minimal backend to get started.
*/

import { Logger } from '@nestjs/common';
import { Logger, ValidationPipe } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { NestFactory } from '@nestjs/core';

Expand All @@ -15,6 +15,11 @@ async function bootstrap() {

const globalPrefix = 'api';
app.setGlobalPrefix(globalPrefix);
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
}),
);

const config = new DocumentBuilder()
.setTitle('Scaffolding API Docs')
Expand Down
33 changes: 33 additions & 0 deletions apps/backend/src/users/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// TODO: Probably want these types to be available to both the frontend and backend in a "common" folder
export enum Status {
MEMBER = 'Member',
RECRUITER = 'Recruiter',
ADMIN = 'Admin',
ALUMNI = 'Alumni',
APPLICANT = 'Applicant',
}

export enum Team {
SFTT = 'Speak For The Trees',
CONSTELLATION = 'Constellation',
JPAL = 'J-PAL',
BREAKTIME = 'Breaktime',
GI = 'Green Infrastructure',
CI = 'Core Infrastructure',
EBOARD = 'E-Board',
}

export enum Role {
DIRECTOR_OF_ENGINEERING = 'Director of Engineering',
DIRECTOR_OF_PRODUCT = 'Director of Product',
DIRECTOR_OF_FINANCE = 'Director of Finance',
DIRECTOR_OF_MARKETING = 'Director of Marketing',
DIRECTOR_OF_RECRUITMENT = 'Director of Recruitment',
DIRECTOR_OF_OPERATIONS = 'Director of Operations',
DIRECTOR_OF_EVENTS = 'Director of Events',
DIRECTOR_OF_DESIGN = 'Director of Design',
PRODUCT_MANAGER = 'Product Manager',
PRODUCT_DESIGNER = 'Product Designer',
TECH_LEAD = 'Technical Lead',
DEVELOPER = 'Developer',
}
50 changes: 50 additions & 0 deletions apps/backend/src/users/update-user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Status, Role, Team } from './types';
import {
IsEmail,
IsOptional,
IsEnum,
IsArray,
ArrayMinSize,
ArrayUnique,
IsUrl,
} from 'class-validator';

export class UpdateUserDTO {
@IsOptional()
@IsEnum(Status)
status?: Status;

@IsOptional()
@IsEmail()
email?: string;

@IsOptional()
profilePicture?: string;

@IsOptional()
@IsUrl({
protocols: ['https'],
require_protocol: true,
host_whitelist: ['www.linkedin.com'],
})
linkedin?: string;

@IsOptional()
@IsUrl({
protocols: ['https'],
require_protocol: true,
host_whitelist: ['github.com'],
})
github?: string;

@IsOptional()
@IsEnum(Team)
team?: Team;

@IsOptional()
@IsArray()
@ArrayMinSize(1)
@ArrayUnique()
@IsEnum(Role, { each: true })
role?: Role[];
}
38 changes: 38 additions & 0 deletions apps/backend/src/users/user.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { IsEmail, IsUrl } from 'class-validator';
import { Entity, Column } from 'typeorm';
import { Role, Status, Team } from './types';

@Entity()
export class User {
@Column({ primary: true })
userId: number;

@Column()
status: Status;

@Column()
firstName: string;

@Column()
lastName: string;

@Column()
@IsEmail()
email: string;

@Column()
profilePicture: string | null;

@Column()
@IsUrl()
linkedin: string | null;

@Column()
github: string | null;

@Column()
team: Team | null;

@Column()
role: Role[] | null;
}
40 changes: 40 additions & 0 deletions apps/backend/src/users/users.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
DefaultValuePipe,
ParseBoolPipe,
ParseIntPipe,
Query,
Body,
Controller,
Get,
Param,
Patch,
} from '@nestjs/common';
import { UpdateUserDTO } from './update-user.dto';
import { UsersService } from './users.service';
import { User } from './user.entity';

@Controller('users')
export class UsersController {
constructor(private readonly usersService: UsersService) {}

@Get()
getAllMembers(
@Query('getAllMembers', new DefaultValuePipe(false), ParseBoolPipe)
getAllMembers: boolean,
) {
return this.usersService.findAll(getAllMembers);
}

@Get('/:userId')
getUser(@Param('userId', ParseIntPipe) userId: number) {
return this.usersService.findOne(userId);
}

@Patch(':userId')
async updateUser(
@Body() updateUserDTO: UpdateUserDTO,
@Param('userId', ParseIntPipe) userId: number,
): Promise<User> {
return this.usersService.updateUser(updateUserDTO, userId);
}
}
13 changes: 13 additions & 0 deletions apps/backend/src/users/users.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';

import { UsersService } from './users.service';
import { UsersController } from './users.controller';
import { User } from './user.entity';

@Module({
imports: [TypeOrmModule.forFeature([User])],
providers: [UsersService],
controllers: [UsersController],
})
export class UsersModule {}
Loading

0 comments on commit 8c5fa6f

Please sign in to comment.