First commit
This commit is contained in:
82
.gitea/workflows/build_and_test.yaml
Normal file
82
.gitea/workflows/build_and_test.yaml
Normal file
@@ -0,0 +1,82 @@
|
||||
name: 'API Build'
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
environment_name:
|
||||
required: true
|
||||
type: string
|
||||
version_number:
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
runs-on: ubuntu-latest
|
||||
environment: ${{ inputs.environment_name }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
sparse-checkout: |
|
||||
api
|
||||
client
|
||||
|
||||
- name: Get Secrets from Infisical
|
||||
uses: Infisical/secrets-action@v1.0.16
|
||||
with:
|
||||
domain: ${{ secrets.INFISICAL_DOMAIN }}
|
||||
client-id: ${{ secrets.INFISICAL_CLIENT_ID }}
|
||||
client-secret: ${{ secrets.INFISICAL_CLIENT_SECRET }}
|
||||
project-slug: ${{ secrets.INFISICAL_PROJECT_SLUG }}
|
||||
env-slug: ${{ inputs.environment_name }}
|
||||
secret-path: /portfolio
|
||||
|
||||
- name: Install Nest CLI
|
||||
run: |
|
||||
npm install -g @nestjs/cli
|
||||
|
||||
- name: 'Setup Node'
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
npm ci
|
||||
|
||||
- name: Build API
|
||||
run: |
|
||||
npm run build -w api
|
||||
|
||||
- name: Test API
|
||||
run: |
|
||||
npm run test -w api
|
||||
|
||||
- name: Build Client
|
||||
env:
|
||||
VITE_API_URL: ${{ env.VITE_API_URL }}
|
||||
VITE_BASE_URL: ${{ env.VITE_BASE_URL }}
|
||||
VITE_CLIENT_ID: ${{ env.VITE_CLIENT_ID }}
|
||||
VITE_ISSUER_URI: ${{ env.VITE_ISSUER_URI }}
|
||||
VITE_TENANT_ID: ${{ env.VITE_TENANT_ID }}
|
||||
run: |
|
||||
npm run build -w client
|
||||
|
||||
- name: Log into Docker Hub
|
||||
if: ${{ github.event_name != 'pull_request' }}
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ env.DOCKERHUB_USERNAME }}
|
||||
password: ${{ env.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Setup Docker Buildx
|
||||
if: ${{ github.event_name != 'pull_request' }}
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build and push to registry
|
||||
if: ${{ github.event_name != 'pull_request' }}
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
push: true
|
||||
tags: noahspan/flying:${{ inputs.version_number }}
|
||||
context: .
|
||||
38
.gitea/workflows/changes.yaml
Normal file
38
.gitea/workflows/changes.yaml
Normal file
@@ -0,0 +1,38 @@
|
||||
name: Changes
|
||||
on:
|
||||
workflow_call:
|
||||
outputs:
|
||||
api:
|
||||
value: ${{ jobs.changes.outputs.api }}
|
||||
client:
|
||||
value: ${{ jobs.changes.outputs.client }}
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
changes:
|
||||
name: filter
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
api: ${{ steps.filter.outputs.api }}
|
||||
client: ${{ steps.filter.outputs.client }}
|
||||
steps:
|
||||
- name: 'Setup Node'
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: '22.x'
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: dorny/paths-filter@v3
|
||||
id: filter
|
||||
with:
|
||||
filters: |
|
||||
api:
|
||||
- 'api/**'
|
||||
client:
|
||||
- 'client/**'
|
||||
infrastructure:
|
||||
- 'infrastructure/**'
|
||||
44
.gitea/workflows/deploy.yaml
Normal file
44
.gitea/workflows/deploy.yaml
Normal file
@@ -0,0 +1,44 @@
|
||||
name: Deploy
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
app_name:
|
||||
required: true
|
||||
type: string
|
||||
environment_name:
|
||||
required: true
|
||||
type: string
|
||||
version_number:
|
||||
required: true
|
||||
type: string
|
||||
|
||||
permissions:
|
||||
id-token: write
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
environment: ${{ inputs.environment_name }}
|
||||
steps:
|
||||
- name: Get Secrets from Infisical
|
||||
uses: Infisical/secrets-action@v1.0.16
|
||||
with:
|
||||
domain: ${{ secrets.INFISICAL_DOMAIN }}
|
||||
client-id: ${{ secrets.INFISICAL_CLIENT_ID }}
|
||||
client-secret: ${{ secrets.INFISICAL_CLIENT_SECRET }}
|
||||
project-slug: ${{ secrets.INFISICAL_PROJECT_SLUG }}
|
||||
env-slug: ${{ inputs.environment_name }}
|
||||
secret-path: /portfolio
|
||||
|
||||
- name: Install Azure CLI
|
||||
run: |
|
||||
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
|
||||
|
||||
- name: Log in to Azure
|
||||
run: |
|
||||
az login --service-principal --username ${{ env.AZURE_CLIENT_ID }} --password ${{ env.AZURE_CLIENT_SECRET }} --tenant ${{ env.AZURE_TENANT_ID }}
|
||||
|
||||
- name: Update Container App
|
||||
run: |
|
||||
az containerapp update --name ${{ inputs.app_name }}-${{ inputs.environment_name }} --container-name ${{ inputs.app_name }} --resource-group ${{ env.RESOURCE_GROUP }} --image docker.io/noahspan/${{ inputs.app_name }}:${{ inputs.version_number }}
|
||||
32
.gitea/workflows/main.yaml
Normal file
32
.gitea/workflows/main.yaml
Normal file
@@ -0,0 +1,32 @@
|
||||
name: Main
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
changes:
|
||||
uses: ./.gitea/workflows/changes.yaml
|
||||
|
||||
build-and-test:
|
||||
if: ${{ needs.changes.outputs.api == 'true' || needs.changes.outputs.client == 'true' }}
|
||||
name: build-and-test
|
||||
needs:
|
||||
- changes
|
||||
uses: ./.gitea/workflows/build_and_test.yaml
|
||||
with:
|
||||
environment_name: test
|
||||
version_number: ${{ github.run_id }}
|
||||
secrets: inherit
|
||||
|
||||
deploy:
|
||||
name: deploy
|
||||
needs:
|
||||
- changes
|
||||
- build-and-test
|
||||
uses: ./.gitea/workflows/deploy.yaml
|
||||
with:
|
||||
app_name: flying
|
||||
environment_name: test
|
||||
version_number: ${{ github.run_id }}
|
||||
secrets: inherit
|
||||
19
.gitea/workflows/pull_request.yaml
Normal file
19
.gitea/workflows/pull_request.yaml
Normal file
@@ -0,0 +1,19 @@
|
||||
name: Pull Request
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
changes:
|
||||
uses: ./.gitea/workflows/changes.yaml
|
||||
|
||||
build:
|
||||
if: ${{ needs.changes.outputs.api == 'true' || needs.changes.outputs.client == 'true'}}
|
||||
name: build-and-test
|
||||
needs:
|
||||
- changes
|
||||
uses: ./.gitea/workflows/build_and_test.yaml
|
||||
with:
|
||||
environment_name: test
|
||||
version_number: ${{ github.run_id }}
|
||||
secrets: inherit
|
||||
25
.gitea/workflows/tag.yaml
Normal file
25
.gitea/workflows/tag.yaml
Normal file
@@ -0,0 +1,25 @@
|
||||
name: Tag
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '**'
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
name: build-and-test
|
||||
uses: ./.gitea/workflows/build_and_test.yaml
|
||||
with:
|
||||
environment_name: prod
|
||||
version_number: ${{ github.ref_name }}
|
||||
secrets: inherit
|
||||
|
||||
deploy:
|
||||
name: deploy
|
||||
needs:
|
||||
- build-and-test
|
||||
uses: ./.gitea/workflows/deploy.yaml
|
||||
with:
|
||||
app_name: flying
|
||||
environment_name: prod
|
||||
version_number: ${{ github.ref_name }}
|
||||
secrets: inherit
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.DS_Store
|
||||
*.auto.tfvars
|
||||
25
api/.eslintrc.js
Normal file
25
api/.eslintrc.js
Normal file
@@ -0,0 +1,25 @@
|
||||
module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
project: 'tsconfig.json',
|
||||
tsconfigRootDir: __dirname,
|
||||
sourceType: 'module',
|
||||
},
|
||||
plugins: ['@typescript-eslint/eslint-plugin'],
|
||||
extends: [
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:prettier/recommended',
|
||||
],
|
||||
root: true,
|
||||
env: {
|
||||
node: true,
|
||||
jest: true,
|
||||
},
|
||||
ignorePatterns: ['.eslintrc.js'],
|
||||
rules: {
|
||||
'@typescript-eslint/interface-name-prefix': 'off',
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
},
|
||||
};
|
||||
58
api/.gitignore
vendored
Normal file
58
api/.gitignore
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
# compiled output
|
||||
/dist
|
||||
/node_modules
|
||||
/build
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
pnpm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
|
||||
# Tests
|
||||
/coverage
|
||||
/.nyc_output
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# temp directory
|
||||
.temp
|
||||
.tmp
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
local.settings.json
|
||||
4
api/.prettierrc
Normal file
4
api/.prettierrc
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
||||
0
api/README.md
Normal file
0
api/README.md
Normal file
8
api/nest-cli.json
Normal file
8
api/nest-cli.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/nest-cli",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {
|
||||
"deleteOutDir": true
|
||||
}
|
||||
}
|
||||
87
api/package.json
Normal file
87
api/package.json
Normal file
@@ -0,0 +1,87 @@
|
||||
{
|
||||
"name": "api",
|
||||
"version": "1.2.0",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json",
|
||||
"typeorm": "npm run build && npx typeorm -d dist/database/data-source.js",
|
||||
"migration:generate": "npm run typeorm -- migration:generate",
|
||||
"migration:run": "npm run typeorm -- migration:run",
|
||||
"migration:revert": "npm run typeorm -- migration:revert",
|
||||
"migration:show": "npm run typeorm -- migration:show",
|
||||
"seed": "npm run build && typeorm-extension seed:run -d ./database/data-source.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/axios": "^4.0.0",
|
||||
"@nestjs/common": "^11.0.11",
|
||||
"@nestjs/config": "^4.0.1",
|
||||
"@nestjs/core": "^11.0.11",
|
||||
"@nestjs/platform-express": "^11.0.11",
|
||||
"@nestjs/typeorm": "^11.0.1",
|
||||
"@noahspan/noahspan-modules": "^1.2.11",
|
||||
"axios": "^1.7.9",
|
||||
"better-sqlite3": "^12.2.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "7.8.2",
|
||||
"uuid": "^11.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/schematics": "^19.1.4",
|
||||
"@nestjs/cli": "^11.0.5",
|
||||
"@nestjs/schematics": "^11.0.2",
|
||||
"@nestjs/testing": "^11.0.11",
|
||||
"@schematics/angular": "^19.1.4",
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/jest": "^29.5.2",
|
||||
"@types/node": "^20.3.1",
|
||||
"@types/supertest": "^6.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
||||
"@typescript-eslint/parser": "^6.0.0",
|
||||
"eslint": "^8.42.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-prettier": "^5.0.0",
|
||||
"jest": "^29.5.0",
|
||||
"prettier": "^3.0.0",
|
||||
"source-map-support": "^0.5.21",
|
||||
"supertest": "^6.3.3",
|
||||
"ts-jest": "^29.1.0",
|
||||
"ts-loader": "^9.4.3",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"typescript": "^5.1.3"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"collectCoverageFrom": [
|
||||
"**/*.(t|j)s"
|
||||
],
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
}
|
||||
}
|
||||
22
api/src/app.controller.spec.ts
Normal file
22
api/src/app.controller.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
});
|
||||
56
api/src/app.module.ts
Normal file
56
api/src/app.module.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { APP_FILTER } from '@nestjs/core';
|
||||
import { HttpExceptionFilter } from './filters/http-exception.filter';
|
||||
import { ProjectModule } from './project/project.module';
|
||||
import { AuthModule, MsGraphModule } from '@noahspan/noahspan-modules'
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import configuration from './config/configuration';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { dataSourceOptions } from './database/data-source';
|
||||
import { SkillModule } from './skill/skill.module';
|
||||
import { ProfileModule } from './profile/profile.module';
|
||||
import { ExperienceModule } from './experience/experience.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
AuthModule.registerAsync({
|
||||
inject: [ConfigService],
|
||||
imports: [ConfigModule],
|
||||
useFactory: async (configService: ConfigService) => {
|
||||
return {
|
||||
audience: configService.get<string>('audience'),
|
||||
issuerUrl: configService.get<string>('issuer'),
|
||||
jwksUri: configService.get<string>('jwksUri')
|
||||
}
|
||||
}
|
||||
}),
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
load: [configuration]
|
||||
}),
|
||||
ExperienceModule,
|
||||
MsGraphModule.registerAsync({
|
||||
inject: [ConfigService],
|
||||
imports: [ConfigModule],
|
||||
useFactory: async (configService: ConfigService) => {
|
||||
return {
|
||||
authority: configService.get<string>('authority'),
|
||||
clientId: configService.get<string>('clientId'),
|
||||
clientSecret: configService.get<string>('clientSecret'),
|
||||
tenantId: configService.get<string>('tenantId')
|
||||
}
|
||||
}
|
||||
}),
|
||||
ProfileModule,
|
||||
ProjectModule,
|
||||
SkillModule,
|
||||
TypeOrmModule.forRoot(dataSourceOptions),
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: APP_FILTER,
|
||||
useClass: HttpExceptionFilter
|
||||
}
|
||||
]
|
||||
})
|
||||
export class AppModule {}
|
||||
10
api/src/config/configuration.ts
Normal file
10
api/src/config/configuration.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export default () => ({
|
||||
azureStorageConnectionString: process.env.AZURE_STORAGE_CONNECTION_STRING,
|
||||
audience: process.env.AUDIENCE,
|
||||
authority: process.env.AUTHORITY,
|
||||
clientId: process.env.CLIENT_ID,
|
||||
clientSecret: process.env.CLIENT_SECRET,
|
||||
issuer: process.env.ISSUER_URL,
|
||||
jwksUri: process.env.JWKS_URI,
|
||||
tenantId: process.env.TENANT_ID
|
||||
})
|
||||
22
api/src/database/data-source.ts
Normal file
22
api/src/database/data-source.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { DataSource, DataSourceOptions } from 'typeorm';
|
||||
import { config } from 'dotenv';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { SeederOptions } from 'typeorm-extension';
|
||||
|
||||
config();
|
||||
|
||||
const configService: ConfigService = new ConfigService();
|
||||
|
||||
export const dataSourceOptions: DataSourceOptions & SeederOptions = {
|
||||
type: 'better-sqlite3',
|
||||
database: configService.get<string>('DB_PATH'),
|
||||
entities: ['../**/*.entity.js'],
|
||||
migrations: ['dist/database/migrations/**/*.js'],
|
||||
migrationsRun: false,
|
||||
seeds: ['dist/database/seeds/**/*.ts'],
|
||||
synchronize: configService.get<boolean>('DB_SYNC')
|
||||
}
|
||||
|
||||
const dataSource: DataSource = new DataSource(dataSourceOptions);
|
||||
|
||||
export default dataSource;
|
||||
@@ -0,0 +1,60 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class InitialMigration1782738482901 implements MigrationInterface {
|
||||
name = 'InitialMigration1782738482901'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`CREATE TABLE "statuses" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL)`);
|
||||
await queryRunner.query(`CREATE TABLE "skill_categories" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "createdBy" varchar, "updated" datetime NOT NULL DEFAULT (datetime('now')), "updatedBy" varchar, "deleted" datetime, "deletedBy" varchar)`);
|
||||
await queryRunner.query(`CREATE TABLE "skill_levels" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "createdBy" varchar, "updated" datetime NOT NULL DEFAULT (datetime('now')), "updatedBy" varchar, "deleted" datetime, "deletedBy" varchar)`);
|
||||
await queryRunner.query(`CREATE TABLE "skill_ranks" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "weight" integer NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "createdBy" varchar, "updated" datetime NOT NULL DEFAULT (datetime('now')), "updatedBy" varchar, "deleted" datetime, "deletedBy" varchar)`);
|
||||
await queryRunner.query(`CREATE TABLE "skills" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "categoryId" varchar NOT NULL, "levelId" integer NOT NULL, "rankId" integer NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "createdBy" varchar, "updated" datetime NOT NULL DEFAULT (datetime('now')), "updatedBy" varchar, "deleted" datetime, "deletedBy" varchar, CONSTRAINT "REL_168133e3158020b53392549d3e" UNIQUE ("rankId"))`);
|
||||
await queryRunner.query(`CREATE TABLE "projects" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "iconName" varchar NOT NULL, "order" integer NOT NULL, "summary" varchar NOT NULL, "repoUrl" varchar, "siteUrl" varchar, "statusId" integer NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "createdBy" varchar, "updated" datetime NOT NULL DEFAULT (datetime('now')), "updatedBy" varchar, "deleted" datetime, "deletedBy" varchar, CONSTRAINT "REL_5a833dfa646b99b852c67dd859" UNIQUE ("statusId"))`);
|
||||
await queryRunner.query(`CREATE TABLE "experiences" ("id" varchar PRIMARY KEY NOT NULL, "profileId" varchar NOT NULL, "companyName" varchar NOT NULL, "companyGeneric" varchar NOT NULL, "title" varchar NOT NULL, "startDate" datetime NOT NULL, "endDate" datetime, "summary" varchar, "statusId" integer NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "createdBy" varchar, "updated" datetime NOT NULL DEFAULT (datetime('now')), "updatedBy" varchar, "deleted" datetime, "deletedBy" varchar, CONSTRAINT "REL_23dfcd8f2d1b6585b848f840d5" UNIQUE ("statusId"))`);
|
||||
await queryRunner.query(`CREATE TABLE "profiles" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "headline" varchar NOT NULL, "summary" varchar NOT NULL, "statusId" integer NOT NULL, "userId" varchar NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "createdBy" varchar, "updated" datetime NOT NULL DEFAULT (datetime('now')), "updatedBy" varchar, "deleted" datetime, "deletedBy" varchar, CONSTRAINT "REL_a0e37cd676d13d116f73d494ee" UNIQUE ("statusId"))`);
|
||||
await queryRunner.query(`CREATE TABLE "temporary_skills" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "categoryId" varchar NOT NULL, "levelId" integer NOT NULL, "rankId" integer NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "createdBy" varchar, "updated" datetime NOT NULL DEFAULT (datetime('now')), "updatedBy" varchar, "deleted" datetime, "deletedBy" varchar, CONSTRAINT "REL_168133e3158020b53392549d3e" UNIQUE ("rankId"), CONSTRAINT "FK_06d267f85858229c10a01a08ad7" FOREIGN KEY ("categoryId") REFERENCES "skill_categories" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_168133e3158020b53392549d3ee" FOREIGN KEY ("rankId") REFERENCES "skill_ranks" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_cad5a64685c1be599c10bb7fc7b" FOREIGN KEY ("levelId") REFERENCES "skill_levels" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)`);
|
||||
await queryRunner.query(`INSERT INTO "temporary_skills"("id", "name", "categoryId", "levelId", "rankId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy") SELECT "id", "name", "categoryId", "levelId", "rankId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy" FROM "skills"`);
|
||||
await queryRunner.query(`DROP TABLE "skills"`);
|
||||
await queryRunner.query(`ALTER TABLE "temporary_skills" RENAME TO "skills"`);
|
||||
await queryRunner.query(`CREATE TABLE "temporary_projects" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "iconName" varchar NOT NULL, "order" integer NOT NULL, "summary" varchar NOT NULL, "repoUrl" varchar, "siteUrl" varchar, "statusId" integer NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "createdBy" varchar, "updated" datetime NOT NULL DEFAULT (datetime('now')), "updatedBy" varchar, "deleted" datetime, "deletedBy" varchar, CONSTRAINT "REL_5a833dfa646b99b852c67dd859" UNIQUE ("statusId"), CONSTRAINT "FK_5a833dfa646b99b852c67dd8593" FOREIGN KEY ("statusId") REFERENCES "statuses" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)`);
|
||||
await queryRunner.query(`INSERT INTO "temporary_projects"("id", "name", "iconName", "order", "summary", "repoUrl", "siteUrl", "statusId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy") SELECT "id", "name", "iconName", "order", "summary", "repoUrl", "siteUrl", "statusId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy" FROM "projects"`);
|
||||
await queryRunner.query(`DROP TABLE "projects"`);
|
||||
await queryRunner.query(`ALTER TABLE "temporary_projects" RENAME TO "projects"`);
|
||||
await queryRunner.query(`CREATE TABLE "temporary_experiences" ("id" varchar PRIMARY KEY NOT NULL, "profileId" varchar NOT NULL, "companyName" varchar NOT NULL, "companyGeneric" varchar NOT NULL, "title" varchar NOT NULL, "startDate" datetime NOT NULL, "endDate" datetime, "summary" varchar, "statusId" integer NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "createdBy" varchar, "updated" datetime NOT NULL DEFAULT (datetime('now')), "updatedBy" varchar, "deleted" datetime, "deletedBy" varchar, CONSTRAINT "REL_23dfcd8f2d1b6585b848f840d5" UNIQUE ("statusId"), CONSTRAINT "FK_be01c61f0c549f2187b5c05c349" FOREIGN KEY ("profileId") REFERENCES "profiles" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_23dfcd8f2d1b6585b848f840d5e" FOREIGN KEY ("statusId") REFERENCES "statuses" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)`);
|
||||
await queryRunner.query(`INSERT INTO "temporary_experiences"("id", "profileId", "companyName", "companyGeneric", "title", "startDate", "endDate", "summary", "statusId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy") SELECT "id", "profileId", "companyName", "companyGeneric", "title", "startDate", "endDate", "summary", "statusId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy" FROM "experiences"`);
|
||||
await queryRunner.query(`DROP TABLE "experiences"`);
|
||||
await queryRunner.query(`ALTER TABLE "temporary_experiences" RENAME TO "experiences"`);
|
||||
await queryRunner.query(`CREATE TABLE "temporary_profiles" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "headline" varchar NOT NULL, "summary" varchar NOT NULL, "statusId" integer NOT NULL, "userId" varchar NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "createdBy" varchar, "updated" datetime NOT NULL DEFAULT (datetime('now')), "updatedBy" varchar, "deleted" datetime, "deletedBy" varchar, CONSTRAINT "REL_a0e37cd676d13d116f73d494ee" UNIQUE ("statusId"), CONSTRAINT "FK_a0e37cd676d13d116f73d494ee6" FOREIGN KEY ("statusId") REFERENCES "statuses" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)`);
|
||||
await queryRunner.query(`INSERT INTO "temporary_profiles"("id", "name", "headline", "summary", "statusId", "userId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy") SELECT "id", "name", "headline", "summary", "statusId", "userId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy" FROM "profiles"`);
|
||||
await queryRunner.query(`DROP TABLE "profiles"`);
|
||||
await queryRunner.query(`ALTER TABLE "temporary_profiles" RENAME TO "profiles"`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "profiles" RENAME TO "temporary_profiles"`);
|
||||
await queryRunner.query(`CREATE TABLE "profiles" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "headline" varchar NOT NULL, "summary" varchar NOT NULL, "statusId" integer NOT NULL, "userId" varchar NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "createdBy" varchar, "updated" datetime NOT NULL DEFAULT (datetime('now')), "updatedBy" varchar, "deleted" datetime, "deletedBy" varchar, CONSTRAINT "REL_a0e37cd676d13d116f73d494ee" UNIQUE ("statusId"))`);
|
||||
await queryRunner.query(`INSERT INTO "profiles"("id", "name", "headline", "summary", "statusId", "userId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy") SELECT "id", "name", "headline", "summary", "statusId", "userId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy" FROM "temporary_profiles"`);
|
||||
await queryRunner.query(`DROP TABLE "temporary_profiles"`);
|
||||
await queryRunner.query(`ALTER TABLE "experiences" RENAME TO "temporary_experiences"`);
|
||||
await queryRunner.query(`CREATE TABLE "experiences" ("id" varchar PRIMARY KEY NOT NULL, "profileId" varchar NOT NULL, "companyName" varchar NOT NULL, "companyGeneric" varchar NOT NULL, "title" varchar NOT NULL, "startDate" datetime NOT NULL, "endDate" datetime, "summary" varchar, "statusId" integer NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "createdBy" varchar, "updated" datetime NOT NULL DEFAULT (datetime('now')), "updatedBy" varchar, "deleted" datetime, "deletedBy" varchar, CONSTRAINT "REL_23dfcd8f2d1b6585b848f840d5" UNIQUE ("statusId"))`);
|
||||
await queryRunner.query(`INSERT INTO "experiences"("id", "profileId", "companyName", "companyGeneric", "title", "startDate", "endDate", "summary", "statusId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy") SELECT "id", "profileId", "companyName", "companyGeneric", "title", "startDate", "endDate", "summary", "statusId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy" FROM "temporary_experiences"`);
|
||||
await queryRunner.query(`DROP TABLE "temporary_experiences"`);
|
||||
await queryRunner.query(`ALTER TABLE "projects" RENAME TO "temporary_projects"`);
|
||||
await queryRunner.query(`CREATE TABLE "projects" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "iconName" varchar NOT NULL, "order" integer NOT NULL, "summary" varchar NOT NULL, "repoUrl" varchar, "siteUrl" varchar, "statusId" integer NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "createdBy" varchar, "updated" datetime NOT NULL DEFAULT (datetime('now')), "updatedBy" varchar, "deleted" datetime, "deletedBy" varchar, CONSTRAINT "REL_5a833dfa646b99b852c67dd859" UNIQUE ("statusId"))`);
|
||||
await queryRunner.query(`INSERT INTO "projects"("id", "name", "iconName", "order", "summary", "repoUrl", "siteUrl", "statusId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy") SELECT "id", "name", "iconName", "order", "summary", "repoUrl", "siteUrl", "statusId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy" FROM "temporary_projects"`);
|
||||
await queryRunner.query(`DROP TABLE "temporary_projects"`);
|
||||
await queryRunner.query(`ALTER TABLE "skills" RENAME TO "temporary_skills"`);
|
||||
await queryRunner.query(`CREATE TABLE "skills" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "categoryId" varchar NOT NULL, "levelId" integer NOT NULL, "rankId" integer NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "createdBy" varchar, "updated" datetime NOT NULL DEFAULT (datetime('now')), "updatedBy" varchar, "deleted" datetime, "deletedBy" varchar, CONSTRAINT "REL_168133e3158020b53392549d3e" UNIQUE ("rankId"))`);
|
||||
await queryRunner.query(`INSERT INTO "skills"("id", "name", "categoryId", "levelId", "rankId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy") SELECT "id", "name", "categoryId", "levelId", "rankId", "created", "createdBy", "updated", "updatedBy", "deleted", "deletedBy" FROM "temporary_skills"`);
|
||||
await queryRunner.query(`DROP TABLE "temporary_skills"`);
|
||||
await queryRunner.query(`DROP TABLE "profiles"`);
|
||||
await queryRunner.query(`DROP TABLE "experiences"`);
|
||||
await queryRunner.query(`DROP TABLE "projects"`);
|
||||
await queryRunner.query(`DROP TABLE "skills"`);
|
||||
await queryRunner.query(`DROP TABLE "skill_ranks"`);
|
||||
await queryRunner.query(`DROP TABLE "skill_levels"`);
|
||||
await queryRunner.query(`DROP TABLE "skill_categories"`);
|
||||
await queryRunner.query(`DROP TABLE "statuses"`);
|
||||
}
|
||||
|
||||
}
|
||||
20
api/src/database/seeds/skill_levels.ts
Normal file
20
api/src/database/seeds/skill_levels.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Seeder } from 'typeorm-extension';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { SkillLevelEntity } from '../../skill/skill-level.entity'
|
||||
|
||||
export default class SkillLevelsSeeder implements Seeder {
|
||||
public async run(dataSource: DataSource): Promise<void> {
|
||||
const repository = dataSource.getRepository(SkillLevelEntity);
|
||||
|
||||
const skillLevels = [
|
||||
{
|
||||
name: 'Experienced'
|
||||
},
|
||||
{
|
||||
name: 'Familiar'
|
||||
}
|
||||
]
|
||||
|
||||
await repository.save(skillLevels);
|
||||
}
|
||||
}
|
||||
26
api/src/database/seeds/skill_ranks.ts
Normal file
26
api/src/database/seeds/skill_ranks.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Seeder } from 'typeorm-extension';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { SkillRankEntity } from '../../skill/skill-rank.entity'
|
||||
|
||||
export default class SkillRanksSeeder implements Seeder {
|
||||
public async run(dataSource: DataSource): Promise<void> {
|
||||
const repository = dataSource.getRepository(SkillRankEntity);
|
||||
|
||||
const skillRanks = [
|
||||
{
|
||||
name: 'High',
|
||||
weight: 3
|
||||
},
|
||||
{
|
||||
name: 'Medium',
|
||||
weight: 2
|
||||
},
|
||||
{
|
||||
name: 'Low',
|
||||
weight: 1
|
||||
}
|
||||
]
|
||||
|
||||
await repository.save(skillRanks);
|
||||
}
|
||||
}
|
||||
20
api/src/database/seeds/statuses.ts
Normal file
20
api/src/database/seeds/statuses.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Seeder } from 'typeorm-extension';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { StatusEntity } from '../../status/status.entity'
|
||||
|
||||
export default class StatusesSeeder implements Seeder {
|
||||
public async run(dataSource: DataSource): Promise<void> {
|
||||
const repository = dataSource.getRepository(StatusEntity);
|
||||
|
||||
const statuses = [
|
||||
{
|
||||
name: 'Draft'
|
||||
},
|
||||
{
|
||||
name: 'Published'
|
||||
}
|
||||
]
|
||||
|
||||
await repository.save(statuses);
|
||||
}
|
||||
}
|
||||
0
api/src/experience/experience.controller.spec.ts
Normal file
0
api/src/experience/experience.controller.spec.ts
Normal file
69
api/src/experience/experience.controller.ts
Normal file
69
api/src/experience/experience.controller.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { Body, Controller, Delete, Get, HttpException, Param, Post, Put } from "@nestjs/common";
|
||||
import { ExperienceService } from "./experience.service";
|
||||
import { CustomError } from "@noahspan/noahspan-modules";
|
||||
import { ExperienceDto } from "./experience.dto";
|
||||
|
||||
@Controller('experiences')
|
||||
export class ExperienceController {
|
||||
constructor(private readonly experienceService: ExperienceService) {}
|
||||
|
||||
@Get(':id')
|
||||
async find(@Param('id') id: string) {
|
||||
try {
|
||||
return await this.experienceService.find(id);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll() {
|
||||
try {
|
||||
return await this.experienceService.findAll();
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@Body() experienceDto: ExperienceDto): Promise<ExperienceDto> {
|
||||
try {
|
||||
return await this.experienceService.create(experienceDto);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
console.log(error)
|
||||
throw new HttpException(customError.message, customError.statusCode)
|
||||
}
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Body() ExperienceDto: ExperienceDto
|
||||
) {
|
||||
try {
|
||||
return await this.experienceService.update(id, ExperienceDto);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode)
|
||||
}
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async delete(
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
try {
|
||||
return await this.experienceService.delete(id);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
13
api/src/experience/experience.dto.ts
Normal file
13
api/src/experience/experience.dto.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export class ExperienceDto {
|
||||
companyName: string;
|
||||
companyNameGeneric: string;
|
||||
location: string;
|
||||
title: string;
|
||||
startDate: Date;
|
||||
endDate?: Date;
|
||||
summary: string;
|
||||
skills?: [];
|
||||
createdBy?: string;
|
||||
updatedBy?: string;
|
||||
deletedBy?: string;
|
||||
}
|
||||
63
api/src/experience/experience.entity.ts
Normal file
63
api/src/experience/experience.entity.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { ProfileEntity } from '../profile/profile.entity'
|
||||
import { SkillEntity } from 'src/skill/skill.entity';
|
||||
import { StatusEntity } from 'src/status/status.entity';
|
||||
import { Entity, PrimaryGeneratedColumn, Column, JoinColumn, ManyToOne, OneToMany, OneToOne, CreateDateColumn, UpdateDateColumn, DeleteDateColumn } from 'typeorm';
|
||||
|
||||
@Entity({ name: 'experiences' })
|
||||
export class ExperienceEntity {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column()
|
||||
profileId: string;
|
||||
|
||||
@Column()
|
||||
companyName: string;
|
||||
|
||||
@Column()
|
||||
companyGeneric: string
|
||||
|
||||
@Column()
|
||||
title: string;
|
||||
|
||||
@Column()
|
||||
startDate: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
endDate: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
summary: string | null
|
||||
|
||||
@Column()
|
||||
statusId: number;
|
||||
|
||||
@CreateDateColumn()
|
||||
created: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
createdBy: string;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updated: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
updatedBy: string;
|
||||
|
||||
@DeleteDateColumn()
|
||||
deleted: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
deletedBy: string;
|
||||
|
||||
@OneToMany(() => SkillEntity, (skill: SkillEntity) => skill.name )
|
||||
skills: SkillEntity[];
|
||||
|
||||
@ManyToOne(() => ProfileEntity, (profile: ProfileEntity) => profile.experiences)
|
||||
@JoinColumn({ name: 'profileId' })
|
||||
profile: ProfileEntity;
|
||||
|
||||
@OneToOne(() => StatusEntity, (status: StatusEntity) => status.name )
|
||||
@JoinColumn({ name: 'statusId' })
|
||||
status: StatusEntity;
|
||||
}
|
||||
16
api/src/experience/experience.module.ts
Normal file
16
api/src/experience/experience.module.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
import { ExperienceEntity } from "./experience.entity";
|
||||
import { ExperienceController } from "./experience.controller";
|
||||
import { ExperienceService } from "./experience.service";
|
||||
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([ExperienceEntity])
|
||||
],
|
||||
controllers: [ExperienceController],
|
||||
exports: [ExperienceService],
|
||||
providers: [ExperienceService]
|
||||
})
|
||||
export class ExperienceModule {}
|
||||
51
api/src/experience/experience.service.spec.ts
Normal file
51
api/src/experience/experience.service.spec.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { getRepositoryToken } from "@nestjs/typeorm";
|
||||
import { ExperienceService } from "./experience.service"
|
||||
import { ExperienceEntity } from './experience.entity'
|
||||
|
||||
describe('ExperienceService', () => {
|
||||
let service: ExperienceService;
|
||||
|
||||
const mockExperienceRepository = {
|
||||
delete: jest.fn(),
|
||||
find: jest.fn(),
|
||||
findOneBy: jest.fn(),
|
||||
save: jest.fn()
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
ExperienceService,
|
||||
{
|
||||
provide: getRepositoryToken(ExperienceEntity),
|
||||
useValue: mockExperienceRepository
|
||||
}
|
||||
]
|
||||
}).compile();
|
||||
|
||||
service = module.get<ExperienceService>(ExperienceService);
|
||||
})
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
})
|
||||
|
||||
it('find => should find one experience by id', async () => {
|
||||
|
||||
})
|
||||
|
||||
it('findAll => should find all experiences', () => {
|
||||
|
||||
})
|
||||
|
||||
it('create => should create a new experience', () => {
|
||||
|
||||
})
|
||||
|
||||
it('update => should update an experience', () => {
|
||||
|
||||
})
|
||||
|
||||
it('delete => should delete an experience')
|
||||
})
|
||||
43
api/src/experience/experience.service.ts
Normal file
43
api/src/experience/experience.service.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ExperienceEntity } from './experience.entity';
|
||||
import { ExperienceDto } from './experience.dto';
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { DeleteResult, Repository } from "typeorm";
|
||||
|
||||
@Injectable()
|
||||
export class ExperienceService {
|
||||
constructor(
|
||||
@InjectRepository(ExperienceEntity) private readonly experienceRepository: Repository<ExperienceEntity>
|
||||
) {}
|
||||
|
||||
async find(id: string): Promise<ExperienceEntity> {
|
||||
return await this.experienceRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: ['profile', 'status']
|
||||
})
|
||||
}
|
||||
|
||||
async findAll(): Promise<ExperienceEntity[]> {
|
||||
return await this.experienceRepository.find({
|
||||
relations: ['profile', 'status']
|
||||
});
|
||||
}
|
||||
|
||||
async create(experience: ExperienceDto): Promise<ExperienceDto> {
|
||||
return await this.experienceRepository.save(experience);
|
||||
}
|
||||
|
||||
async update(
|
||||
id: string,
|
||||
experienceDto: ExperienceDto
|
||||
): Promise<ExperienceDto> {
|
||||
const experienceEntity: ExperienceEntity = await this.experienceRepository.findOneBy({ id })
|
||||
const experienceEntityUpdated = Object.assign(experienceEntity, experienceDto)
|
||||
|
||||
return await this.experienceRepository.save(experienceEntityUpdated)
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<DeleteResult> {
|
||||
return await this.experienceRepository.delete({ id })
|
||||
}
|
||||
}
|
||||
25
api/src/filters/http-exception.filter.ts
Normal file
25
api/src/filters/http-exception.filter.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import {
|
||||
ExceptionFilter,
|
||||
Catch,
|
||||
ArgumentsHost,
|
||||
HttpException
|
||||
} from '@nestjs/common';
|
||||
import { Request, Response } from 'express';
|
||||
|
||||
@Catch(HttpException)
|
||||
export class HttpExceptionFilter implements ExceptionFilter {
|
||||
catch(excpetion: HttpException, host: ArgumentsHost) {
|
||||
const ctx = host.switchToHttp();
|
||||
const response = ctx.getResponse<Response>();
|
||||
const request = ctx.getRequest<Request>();
|
||||
const status = excpetion.getStatus();
|
||||
|
||||
response.status(status).json({
|
||||
name: excpetion.cause,
|
||||
message: excpetion.message,
|
||||
statusCode: status,
|
||||
timestamp: new Date().toISOString(),
|
||||
path: request.url
|
||||
});
|
||||
}
|
||||
}
|
||||
3
api/src/index.css
Normal file
3
api/src/index.css
Normal file
@@ -0,0 +1,3 @@
|
||||
body {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
27
api/src/main.ts
Normal file
27
api/src/main.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { HttpService } from '@nestjs/axios';
|
||||
import { HttpExceptionFilter } from './filters/http-exception.filter';
|
||||
import { InternalServerErrorException } from '@nestjs/common';
|
||||
|
||||
async function bootstrap() {
|
||||
const httpService = new HttpService();
|
||||
const app = await NestFactory.create(AppModule);
|
||||
|
||||
app.enableCors();
|
||||
app.setGlobalPrefix('api');
|
||||
app.useGlobalFilters(new HttpExceptionFilter());
|
||||
httpService.axiosRef.interceptors.response.use(
|
||||
(response) => {
|
||||
return response;
|
||||
},
|
||||
(error) => {
|
||||
console.error('Internal server error exception', error);
|
||||
|
||||
throw new InternalServerErrorException();
|
||||
}
|
||||
);
|
||||
|
||||
await app.listen(3000);
|
||||
}
|
||||
bootstrap();
|
||||
0
api/src/profile/profile.controller.spec.ts
Normal file
0
api/src/profile/profile.controller.spec.ts
Normal file
87
api/src/profile/profile.controller.ts
Normal file
87
api/src/profile/profile.controller.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpException,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
UseGuards
|
||||
} from '@nestjs/common';
|
||||
import { ProfileDto } from './profile.dto';
|
||||
import { ProfileEntity } from './profile.entity';
|
||||
import { ProfileService } from './profile.service';
|
||||
import { AuthGuard, CustomError, Public } from '@noahspan/noahspan-modules';
|
||||
|
||||
@Controller('profiles')
|
||||
export class ProfileController {
|
||||
constructor(private readonly profileService: ProfileService) {}
|
||||
|
||||
@Get(':id')
|
||||
// @UseGuards(AuthGuard)
|
||||
async find(
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
try {
|
||||
return await this.profileService.find(id);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
console.log(error)
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll() {
|
||||
try {
|
||||
return await this.profileService.findAll();
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Post()
|
||||
// @UseGuards(AuthGuard)
|
||||
async create(@Body() profileDto: ProfileDto) {
|
||||
try {
|
||||
console.log(profileDto)
|
||||
return await this.profileService.create(profileDto);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
console.log(customError)
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@UseGuards(AuthGuard)
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Body() profileDto: ProfileDto
|
||||
) {
|
||||
try {
|
||||
return await this.profileService.update(id, profileDto);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@UseGuards(AuthGuard)
|
||||
async delete(
|
||||
@Param('id') id: string
|
||||
) {
|
||||
try {
|
||||
return await this.profileService.delete(id);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
10
api/src/profile/profile.dto.ts
Normal file
10
api/src/profile/profile.dto.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export class ProfileDto {
|
||||
name: string;
|
||||
headline: string;
|
||||
summary: string;
|
||||
userId: string;
|
||||
statusId: number;
|
||||
createdBy?: string;
|
||||
updatedBy?: string;
|
||||
deletedBy?: string;
|
||||
}
|
||||
53
api/src/profile/profile.entity.ts
Normal file
53
api/src/profile/profile.entity.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { ExperienceEntity } from 'src/experience/experience.entity';
|
||||
import { SkillEntity } from 'src/skill/skill.entity';
|
||||
import { StatusEntity } from 'src/status/status.entity';
|
||||
import { Entity, PrimaryGeneratedColumn, Column, OneToMany, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, OneToOne, JoinColumn } from 'typeorm';
|
||||
|
||||
@Entity({ name: 'profiles' })
|
||||
export class ProfileEntity {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
headline: string;
|
||||
|
||||
@Column()
|
||||
summary: string;
|
||||
|
||||
@Column()
|
||||
statusId: number;
|
||||
|
||||
@Column()
|
||||
userId: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
created: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
createdBy: string;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updated: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
updatedBy: string
|
||||
|
||||
@DeleteDateColumn()
|
||||
deleted: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
deletedBy: string;
|
||||
|
||||
@OneToMany(() => ExperienceEntity, (experience: ExperienceEntity) => experience.profile)
|
||||
experiences: ExperienceEntity[]
|
||||
|
||||
@OneToMany(() => SkillEntity, (skill: SkillEntity) => skill.name )
|
||||
skills: SkillEntity[];
|
||||
|
||||
@OneToOne(() => StatusEntity, (status: StatusEntity) => status.name )
|
||||
@JoinColumn({ name: 'statusId' })
|
||||
status: StatusEntity;
|
||||
}
|
||||
15
api/src/profile/profile.module.ts
Normal file
15
api/src/profile/profile.module.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
import { ProfileController } from "./profile.controller";
|
||||
import { ProfileEntity } from "./profile.entity";
|
||||
import { ProfileService } from "./profile.service";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([ProfileEntity])
|
||||
],
|
||||
controllers: [ProfileController],
|
||||
exports: [ProfileService],
|
||||
providers: [ProfileService]
|
||||
})
|
||||
export class ProfileModule {}
|
||||
0
api/src/profile/profile.service.spec.ts
Normal file
0
api/src/profile/profile.service.spec.ts
Normal file
46
api/src/profile/profile.service.ts
Normal file
46
api/src/profile/profile.service.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ProfileEntity } from './profile.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { DeleteResult, Repository } from 'typeorm';
|
||||
import { ProfileDto } from './profile.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ProfileService {
|
||||
constructor(
|
||||
@InjectRepository(ProfileEntity) private readonly profileRepository: Repository<ProfileEntity>,
|
||||
) {}
|
||||
|
||||
async find(id: string): Promise<ProfileEntity> {
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: ['status']
|
||||
});
|
||||
|
||||
console.log(profile);
|
||||
return profile;
|
||||
}
|
||||
|
||||
async findAll(): Promise<ProfileEntity[]> {
|
||||
return await this.profileRepository.find({
|
||||
relations: ['status']
|
||||
});
|
||||
}
|
||||
|
||||
async create(profile: ProfileDto): Promise<ProfileDto> {
|
||||
return await this.profileRepository.save(profile);
|
||||
}
|
||||
|
||||
async update(
|
||||
id: string,
|
||||
profileDto: ProfileDto
|
||||
): Promise<ProfileDto> {
|
||||
const profileEntity: ProfileEntity = await this.profileRepository.findOneBy({ id })
|
||||
const profileEntityUpdated = Object.assign(profileEntity, profileDto)
|
||||
|
||||
return await this.profileRepository.save(profileEntityUpdated);
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<DeleteResult> {
|
||||
return await this.profileRepository.delete({ id });
|
||||
}
|
||||
}
|
||||
70
api/src/project/project.controller.spec.ts
Normal file
70
api/src/project/project.controller.spec.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { ProjectController } from "./project.controller"
|
||||
import { ProjectService } from "./project.service";
|
||||
|
||||
|
||||
describe('ProjectController', () => {
|
||||
let controller: ProjectController;
|
||||
|
||||
const mockProjectService = {
|
||||
create: jest.fn(),
|
||||
delete: jest.fn(),
|
||||
find: jest.fn(),
|
||||
findAll: jest.fn(),
|
||||
update: jest.fn()
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [ProjectController],
|
||||
providers: [
|
||||
{
|
||||
provide: ProjectService,
|
||||
useValue: mockProjectService
|
||||
}
|
||||
]
|
||||
}).compile();
|
||||
|
||||
controller = module.get<ProjectController>(ProjectController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
|
||||
it('find => should find a project by id', async () => {
|
||||
const id: string = ''
|
||||
});
|
||||
|
||||
it('find => should fail to find a project by id', async () => {
|
||||
const id: string = ''
|
||||
});
|
||||
|
||||
it('fildAll => should fail to find all projects', async () => {
|
||||
|
||||
});
|
||||
|
||||
it('create => should create a new project', async () => {
|
||||
|
||||
})
|
||||
|
||||
it('create => should fail to create a new project', async () => {
|
||||
|
||||
})
|
||||
|
||||
it('update => should update an existing project', async () => {
|
||||
|
||||
})
|
||||
|
||||
it('update => should fail to update an existing project', async () => {
|
||||
|
||||
})
|
||||
|
||||
it('delete => should delete an existing project', async () => {
|
||||
|
||||
})
|
||||
|
||||
it('delete => should failt to delete an existing project', async () => {
|
||||
|
||||
})
|
||||
})
|
||||
87
api/src/project/project.controller.ts
Normal file
87
api/src/project/project.controller.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpException,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
UseGuards
|
||||
} from '@nestjs/common';
|
||||
import { ProjectDto } from './project.dto';
|
||||
import { ProjectEntity } from './project.entity';
|
||||
import { ProjectService } from './project.service';
|
||||
import { AuthGuard, CustomError, Public } from '@noahspan/noahspan-modules';
|
||||
|
||||
@Controller('projects')
|
||||
export class ProjectController {
|
||||
constructor(private readonly projectService: ProjectService) {}
|
||||
|
||||
@Get(':id')
|
||||
@UseGuards(AuthGuard)
|
||||
async find(
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
try {
|
||||
return await this.projectService.find(id);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll() {
|
||||
try {
|
||||
return await this.projectService.findAll();
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Post()
|
||||
// @UseGuards(AuthGuard)
|
||||
async create(@Body() projectDto: ProjectDto) {
|
||||
try {
|
||||
console.log(projectDto)
|
||||
return await this.projectService.create(projectDto);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
console.log(customError)
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@UseGuards(AuthGuard)
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Body() projectDto: ProjectDto
|
||||
) {
|
||||
try {
|
||||
return await this.projectService.update(id, projectDto);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@UseGuards(AuthGuard)
|
||||
async delete(
|
||||
@Param('id') id: string
|
||||
) {
|
||||
try {
|
||||
return await this.projectService.delete(id);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
api/src/project/project.dto.ts
Normal file
13
api/src/project/project.dto.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export class ProjectDto {
|
||||
id: string;
|
||||
name: string;
|
||||
icon: string;
|
||||
order: number;
|
||||
summary: string;
|
||||
repoUrl?: string;
|
||||
siteUrl?: string;
|
||||
skills?: [];
|
||||
createdBy?: string;
|
||||
updatedBy?: string;
|
||||
deletedBy?: string;
|
||||
}
|
||||
55
api/src/project/project.entity.ts
Normal file
55
api/src/project/project.entity.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { SkillEntity } from 'src/skill/skill.entity';
|
||||
import { StatusEntity } from 'src/status/status.entity';
|
||||
import { Entity, PrimaryGeneratedColumn, Column, OneToMany, OneToOne, JoinColumn, CreateDateColumn, UpdateDateColumn, DeleteDateColumn } from 'typeorm';
|
||||
|
||||
@Entity({ name: 'projects' })
|
||||
export class ProjectEntity {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@Column()
|
||||
iconName: string
|
||||
|
||||
@Column()
|
||||
order: number;
|
||||
|
||||
@Column()
|
||||
summary: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
repoUrl?: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
siteUrl?: string;
|
||||
|
||||
@Column()
|
||||
statusId: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
created: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
createdBy: string;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updated: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
updatedBy: string;
|
||||
|
||||
@DeleteDateColumn()
|
||||
deleted: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
deletedBy: string
|
||||
|
||||
@OneToMany(() => SkillEntity, (skill: SkillEntity) => skill.name )
|
||||
skills: SkillEntity[];
|
||||
|
||||
@OneToOne(() => StatusEntity, (status: StatusEntity) => status.name )
|
||||
@JoinColumn({ name: 'statusId' })
|
||||
status: StatusEntity;
|
||||
}
|
||||
16
api/src/project/project.module.ts
Normal file
16
api/src/project/project.module.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ProjectController } from './project.controller';
|
||||
import { ProjectService } from './project.service';
|
||||
import { ProjectEntity } from './project.entity';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ProjectModule,
|
||||
TypeOrmModule.forFeature([ProjectEntity])
|
||||
],
|
||||
controllers: [ProjectController],
|
||||
providers: [ProjectService]
|
||||
})
|
||||
export class ProjectModule {}
|
||||
54
api/src/project/project.service.spec.ts
Normal file
54
api/src/project/project.service.spec.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { ProjectService } from "./project.service"
|
||||
import { ProjectEntity } from "./project.entity";
|
||||
import { getRepositoryToken } from "@nestjs/typeorm";
|
||||
|
||||
|
||||
describe('ProjectService', () => {
|
||||
let service: ProjectService;
|
||||
|
||||
const mockProjectRepository = {
|
||||
delete: jest.fn(),
|
||||
find: jest.fn(),
|
||||
findOneBy: jest.fn(),
|
||||
save: jest.fn()
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
ProjectService,
|
||||
{
|
||||
provide: getRepositoryToken(ProjectEntity),
|
||||
useValue: mockProjectRepository
|
||||
}
|
||||
]
|
||||
}).compile();
|
||||
|
||||
service = module.get<ProjectService>(ProjectService);
|
||||
})
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
})
|
||||
|
||||
it('find => should find one project by id', async () => {
|
||||
const id: string = ''
|
||||
})
|
||||
|
||||
it('findAll => should find all projects', async () => {
|
||||
|
||||
})
|
||||
|
||||
it('create => should create a new project', async () => {
|
||||
|
||||
})
|
||||
|
||||
it('update => should update a project', async () => {
|
||||
|
||||
})
|
||||
|
||||
it('delete => should delete a project', async () => {
|
||||
|
||||
})
|
||||
})
|
||||
46
api/src/project/project.service.ts
Normal file
46
api/src/project/project.service.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ProjectEntity } from './project.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { DeleteResult, Repository } from 'typeorm';
|
||||
import { ProjectDto } from './project.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ProjectService {
|
||||
constructor(
|
||||
@InjectRepository(ProjectEntity) private readonly projectRepository: Repository<ProjectEntity>,
|
||||
) {}
|
||||
|
||||
async find(id: string): Promise<ProjectEntity> {
|
||||
const project = await this.projectRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: ['status']
|
||||
});
|
||||
|
||||
console.log(project);
|
||||
return project;
|
||||
}
|
||||
|
||||
async findAll(): Promise<ProjectEntity[]> {
|
||||
return await this.projectRepository.find({
|
||||
relations: ['status']
|
||||
});
|
||||
}
|
||||
|
||||
async create(project: ProjectDto): Promise<ProjectDto> {
|
||||
return await this.projectRepository.save(project);
|
||||
}
|
||||
|
||||
async update(
|
||||
id: string,
|
||||
projectDto: ProjectDto
|
||||
): Promise<ProjectDto> {
|
||||
const projectEntity: ProjectEntity = await this.projectRepository.findOneBy({ id })
|
||||
const projectEntityUpdated = Object.assign(projectEntity, projectDto)
|
||||
|
||||
return await this.projectRepository.save(projectEntityUpdated);
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<DeleteResult> {
|
||||
return await this.projectRepository.delete({ id });
|
||||
}
|
||||
}
|
||||
89
api/src/skill/skill-category.controller.ts
Normal file
89
api/src/skill/skill-category.controller.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpException,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
UseGuards
|
||||
} from '@nestjs/common';
|
||||
import { SkillCategoryDto } from './skill-category.dto';
|
||||
import { SkillCategoryEntity } from './skill-category.entity';
|
||||
import { SkillCategoryService } from './skill-category.service';
|
||||
import { AuthGuard, CustomError, Public } from '@noahspan/noahspan-modules';
|
||||
|
||||
@Controller('skill-categories')
|
||||
export class SkillCategoryController {
|
||||
constructor(private readonly skillCategoryService: SkillCategoryService) {}
|
||||
|
||||
@Get(':id')
|
||||
@UseGuards(AuthGuard)
|
||||
async find(
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
try {
|
||||
return await this.skillCategoryService.find(id);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll() {
|
||||
try {
|
||||
return await this.skillCategoryService.findAll();
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Post()
|
||||
// @UseGuards(AuthGuard)
|
||||
async create(@Body() skillCategoryDto: SkillCategoryDto) {
|
||||
try {
|
||||
console.log(skillCategoryDto)
|
||||
return await this.skillCategoryService.create(skillCategoryDto);
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@UseGuards(AuthGuard)
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Body() skillCategoryDto: SkillCategoryDto
|
||||
) {
|
||||
try {
|
||||
return await this.skillCategoryService.update(id, skillCategoryDto);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
// @UseGuards(AuthGuard)
|
||||
async delete(
|
||||
@Param('id') id: string
|
||||
) {
|
||||
try {
|
||||
return await this.skillCategoryService.delete(id);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
6
api/src/skill/skill-category.dto.ts
Normal file
6
api/src/skill/skill-category.dto.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export class SkillCategoryDto {
|
||||
name: string;
|
||||
createdBy?: string;
|
||||
updatedBy?: string;
|
||||
deletedBy?: string;
|
||||
}
|
||||
33
api/src/skill/skill-category.entity.ts
Normal file
33
api/src/skill/skill-category.entity.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, JoinColumn, CreateDateColumn, UpdateDateColumn, DeleteDateColumn } from 'typeorm';
|
||||
import { SkillEntity } from 'src/skill/skill.entity';
|
||||
import { SkillLevelEntity } from 'src/skill/skill-level.entity';
|
||||
|
||||
@Entity({ name: 'skill_categories' })
|
||||
export class SkillCategoryEntity {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
created: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
createdBy: string;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updated: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
updatedBy: string;
|
||||
|
||||
@DeleteDateColumn()
|
||||
deleted: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
deletedBy: string;
|
||||
|
||||
@OneToMany(() => SkillEntity, (skill: SkillEntity) => skill.name)
|
||||
skills: SkillEntity[];
|
||||
}
|
||||
38
api/src/skill/skill-category.service.ts
Normal file
38
api/src/skill/skill-category.service.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { SkillCategoryDto } from './skill-category.dto';
|
||||
import { SkillCategoryEntity } from './skill-category.entity';
|
||||
import { DeleteResult, Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class SkillCategoryService {
|
||||
constructor(
|
||||
@InjectRepository(SkillCategoryEntity) private readonly skillCategoryRepository: Repository<SkillCategoryEntity>
|
||||
) {}
|
||||
|
||||
async find(id: string): Promise<SkillCategoryEntity> {
|
||||
return await this.skillCategoryRepository.findOneBy({ id })
|
||||
}
|
||||
|
||||
async findAll(): Promise<SkillCategoryEntity[]> {
|
||||
return await this.skillCategoryRepository.find();
|
||||
}
|
||||
|
||||
async create(skillCategory: SkillCategoryDto): Promise<SkillCategoryDto> {
|
||||
return await this.skillCategoryRepository.save(skillCategory)
|
||||
}
|
||||
|
||||
async update(
|
||||
id: string,
|
||||
skillCategoryDto: SkillCategoryDto
|
||||
): Promise<SkillCategoryDto> {
|
||||
const skillCategoryEntity: SkillCategoryEntity = await this.skillCategoryRepository.findOneBy({ id })
|
||||
const skillEntityUpdated = Object.assign(skillCategoryEntity, skillCategoryDto)
|
||||
|
||||
return await this.skillCategoryRepository.save(skillEntityUpdated)
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<DeleteResult> {
|
||||
return await this.skillCategoryRepository.delete({ id })
|
||||
}
|
||||
}
|
||||
24
api/src/skill/skill-level.controller.ts
Normal file
24
api/src/skill/skill-level.controller.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
} from '@nestjs/common';
|
||||
import { SkillLevelService } from './skill-level.service';
|
||||
import { AuthGuard, CustomError, Public } from '@noahspan/noahspan-modules';
|
||||
|
||||
@Controller('skill-levels')
|
||||
export class SkillLevelController {
|
||||
constructor(private readonly skillLevelService: SkillLevelService) {}
|
||||
|
||||
@Get()
|
||||
async findAll() {
|
||||
try {
|
||||
return await this.skillLevelService.findAll();
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
api/src/skill/skill-level.entity.ts
Normal file
33
api/src/skill/skill-level.entity.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, ManyToMany, JoinTable, OneToMany, CreateDateColumn, UpdateDateColumn, DeleteDateColumn } from 'typeorm';
|
||||
import { SkillEntity } from './skill.entity';
|
||||
|
||||
@Entity({ name: 'skill_levels' })
|
||||
export class SkillLevelEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
created: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
createdBy: string;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updated: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
updatedBy: string;
|
||||
|
||||
@DeleteDateColumn()
|
||||
deleted: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
deletedBy: string;
|
||||
|
||||
@OneToMany(() => SkillEntity, (skill: SkillEntity) => skill.name)
|
||||
skills: SkillEntity[];
|
||||
}
|
||||
|
||||
18
api/src/skill/skill-level.service.ts
Normal file
18
api/src/skill/skill-level.service.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { SkillDto } from './skill.dto';
|
||||
import { SkillEntity } from './skill.entity';
|
||||
import { DeleteResult, Repository } from 'typeorm';
|
||||
import { SkillLevelEntity } from "./skill-level.entity";
|
||||
import { SkillRankEntity } from "./skill-rank.entity";
|
||||
|
||||
@Injectable()
|
||||
export class SkillLevelService {
|
||||
constructor(
|
||||
@InjectRepository(SkillLevelEntity) private readonly skillLevelRepository: Repository<SkillLevelEntity>
|
||||
) {}
|
||||
|
||||
async findAll(): Promise<SkillLevelEntity[]> {
|
||||
return await this.skillLevelRepository.find();
|
||||
}
|
||||
}
|
||||
24
api/src/skill/skill-rank.controller.ts
Normal file
24
api/src/skill/skill-rank.controller.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
} from '@nestjs/common';
|
||||
import { SkillRankService } from './skill-rank.service';
|
||||
import { CustomError } from '@noahspan/noahspan-modules';
|
||||
|
||||
@Controller('skill-ranks')
|
||||
export class SkillRankController {
|
||||
constructor(private readonly skillRankService: SkillRankService) {}
|
||||
|
||||
@Get()
|
||||
async findAll() {
|
||||
try {
|
||||
return await this.skillRankService.findAll();
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
api/src/skill/skill-rank.entity.ts
Normal file
31
api/src/skill/skill-rank.entity.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn } from 'typeorm'
|
||||
|
||||
@Entity({ name: 'skill_ranks' })
|
||||
export class SkillRankEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
weight: number;
|
||||
|
||||
@CreateDateColumn()
|
||||
created: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
createdBy: string;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updated: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
updatedBy: string;
|
||||
|
||||
@DeleteDateColumn()
|
||||
deleted: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
deletedBy: string;
|
||||
}
|
||||
18
api/src/skill/skill-rank.service.ts
Normal file
18
api/src/skill/skill-rank.service.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { SkillDto } from './skill.dto';
|
||||
import { SkillEntity } from './skill.entity';
|
||||
import { DeleteResult, Repository } from 'typeorm';
|
||||
import { SkillLevelEntity } from "./skill-level.entity";
|
||||
import { SkillRankEntity } from "./skill-rank.entity";
|
||||
|
||||
@Injectable()
|
||||
export class SkillRankService {
|
||||
constructor(
|
||||
@InjectRepository(SkillRankEntity) private readonly skillRankRepository: Repository<SkillRankEntity>
|
||||
) {}
|
||||
|
||||
async findAll(): Promise<SkillRankEntity[]> {
|
||||
return await this.skillRankRepository.find();
|
||||
}
|
||||
}
|
||||
27
api/src/skill/skill.controller.spec.ts
Normal file
27
api/src/skill/skill.controller.spec.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { getRepositoryToken } from "@nestjs/typeorm";
|
||||
import { ProjectService } from "src/project/project.service";
|
||||
import { SkillSerivce } from './skill.service'
|
||||
import { SkillEntity } from "./skill.entity";
|
||||
|
||||
describe('SkillService', () => {
|
||||
let service: SkillService;
|
||||
|
||||
const mockSkillRepository = {
|
||||
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
ProjectService,
|
||||
{
|
||||
provide: getRepositoryToken(SkillEntity),
|
||||
useValue: mockSkillRepository
|
||||
}
|
||||
]
|
||||
}).compile();
|
||||
|
||||
service = module.get<SkillService>(SkillService);
|
||||
})
|
||||
})
|
||||
110
api/src/skill/skill.controller.ts
Normal file
110
api/src/skill/skill.controller.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpException,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
UseGuards
|
||||
} from '@nestjs/common';
|
||||
import { SkillDto } from './skill.dto';
|
||||
import { SkillEntity } from './skill.entity';
|
||||
import { SkillService } from './skill.service';
|
||||
import { AuthGuard, CustomError, Public } from '@noahspan/noahspan-modules';
|
||||
|
||||
@Controller('skills')
|
||||
export class SkillController {
|
||||
constructor(private readonly skillService: SkillService) {}
|
||||
|
||||
@Get(':id')
|
||||
// @UseGuards(AuthGuard)
|
||||
async find(
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
try {
|
||||
return await this.skillService.find(id);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll() {
|
||||
try {
|
||||
return await this.skillService.findAll();
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Post()
|
||||
// @UseGuards(AuthGuard)
|
||||
async create(@Body() skillDto: SkillDto) {
|
||||
try {
|
||||
console.log(skillDto)
|
||||
return await this.skillService.create(skillDto);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
console.log(customError)
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@UseGuards(AuthGuard)
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Body() projectDto: SkillDto
|
||||
) {
|
||||
try {
|
||||
return await this.skillService.update(id, projectDto);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@UseGuards(AuthGuard)
|
||||
async delete(
|
||||
@Param('id') id: string
|
||||
) {
|
||||
try {
|
||||
return await this.skillService.delete(id);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Get('levels')
|
||||
async levels() {
|
||||
try {
|
||||
return await this.skillService.getLevels();
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode)
|
||||
}
|
||||
}
|
||||
|
||||
@Get('ranks')
|
||||
async ranks() {
|
||||
try {
|
||||
return await this.skillService.getRanks();
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
11
api/src/skill/skill.dto.ts
Normal file
11
api/src/skill/skill.dto.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { SkillLevelEntity } from "./skill-level.entity";
|
||||
|
||||
export class SkillDto {
|
||||
categoryId: string;
|
||||
name: string;
|
||||
levelId: string;
|
||||
rankId: string;
|
||||
createdBy?: string;
|
||||
updatedBy?: string;
|
||||
deletedBy?: string;
|
||||
}
|
||||
52
api/src/skill/skill.entity.ts
Normal file
52
api/src/skill/skill.entity.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { SkillCategoryEntity } from 'src/skill/skill-category.entity';
|
||||
import { Entity, PrimaryGeneratedColumn, Column, JoinColumn, ManyToOne, ManyToMany, OneToOne, CreateDateColumn, UpdateDateColumn, DeleteDateColumn } from 'typeorm';
|
||||
import { SkillLevelEntity } from './skill-level.entity';
|
||||
import { SkillRankEntity } from './skill-rank.entity';
|
||||
|
||||
@Entity({ name: 'skills' })
|
||||
export class SkillEntity {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
categoryId: string;
|
||||
|
||||
@Column()
|
||||
levelId: string
|
||||
|
||||
@Column()
|
||||
rankId: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
created: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
createdBy: string;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updated: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
updatedBy: string;
|
||||
|
||||
@DeleteDateColumn()
|
||||
deleted: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
deletedBy: string;
|
||||
|
||||
@ManyToOne(() => SkillCategoryEntity, (category: SkillCategoryEntity) => category.name)
|
||||
@JoinColumn({ name: 'categoryId' })
|
||||
category: SkillCategoryEntity;
|
||||
|
||||
@OneToOne(() => SkillRankEntity, (rank: SkillRankEntity) => rank.name)
|
||||
@JoinColumn({ name: 'rankId' })
|
||||
rank: SkillRankEntity;
|
||||
|
||||
@ManyToOne(() => SkillLevelEntity, (level: SkillLevelEntity) => level.name)
|
||||
@JoinColumn({ name: 'levelId' })
|
||||
level: SkillLevelEntity;
|
||||
}
|
||||
24
api/src/skill/skill.module.ts
Normal file
24
api/src/skill/skill.module.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { SkillController } from './skill.controller';
|
||||
import { SkillService } from './skill.service';
|
||||
import { SkillEntity } from './skill.entity';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { SkillLevelEntity } from './skill-level.entity';
|
||||
import { SkillCategoryEntity } from './skill-category.entity';
|
||||
import { SkillCategoryController } from './skill-category.controller';
|
||||
import { SkillCategoryService } from './skill-category.service';
|
||||
import { SkillRankEntity } from './skill-rank.entity';
|
||||
import { SkillLevelController } from './skill-level.controller';
|
||||
import { SkillLevelService } from './skill-level.service';
|
||||
import { SkillRankController } from './skill-rank.controller';
|
||||
import { SkillRankService } from './skill-rank.service';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([SkillCategoryEntity, SkillEntity, SkillLevelEntity, SkillRankEntity])
|
||||
],
|
||||
controllers: [SkillCategoryController, SkillController, SkillLevelController, SkillRankController],
|
||||
providers: [SkillCategoryService, SkillService, SkillLevelService, SkillRankService]
|
||||
})
|
||||
export class SkillModule {}
|
||||
53
api/src/skill/skill.service.spec.ts
Normal file
53
api/src/skill/skill.service.spec.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { getRepositoryToken } from "@nestjs/typeorm";
|
||||
import { SkillService } from './skill.service';
|
||||
import { SkillEntity } from "./skill.entity";
|
||||
|
||||
describe('SkillService', () => {
|
||||
let service: SkillService;
|
||||
|
||||
const mockSkillRepository = {
|
||||
delete: jest.fn(),
|
||||
find: jest.fn(),
|
||||
findOneBy: jest.fn(),
|
||||
save: jest.fn()
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
SkillService,
|
||||
{
|
||||
provide: getRepositoryToken(SkillEntity),
|
||||
useValue: mockSkillRepository
|
||||
}
|
||||
]
|
||||
}).compile();
|
||||
|
||||
service = module.get<SkillService>(SkillService);
|
||||
})
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
})
|
||||
|
||||
it('find => should find one skill by id', async () => {
|
||||
|
||||
})
|
||||
|
||||
it('findAll => should fild all skills', async () => {
|
||||
|
||||
})
|
||||
|
||||
it('create => should create a new skill', async () => {
|
||||
|
||||
})
|
||||
|
||||
it('update => should update a skill', async () => {
|
||||
|
||||
})
|
||||
|
||||
it('delete => should delete a skill', async () => {
|
||||
|
||||
})
|
||||
})
|
||||
57
api/src/skill/skill.service.ts
Normal file
57
api/src/skill/skill.service.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { SkillDto } from './skill.dto';
|
||||
import { SkillEntity } from './skill.entity';
|
||||
import { DeleteResult, Repository } from 'typeorm';
|
||||
import { SkillLevelEntity } from "./skill-level.entity";
|
||||
import { SkillRankEntity } from "./skill-rank.entity";
|
||||
|
||||
@Injectable()
|
||||
export class SkillService {
|
||||
constructor(
|
||||
@InjectRepository(SkillEntity) private readonly skillRepository: Repository<SkillEntity>,
|
||||
@InjectRepository(SkillLevelEntity) private readonly skillLevelRepository: Repository<SkillLevelEntity>,
|
||||
@InjectRepository(SkillRankEntity) private readonly skillRankRepository: Repository<SkillRankEntity>
|
||||
) {}
|
||||
|
||||
async find(id: string): Promise<SkillEntity> {
|
||||
return await this.skillRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: ['category', 'rank', 'level']
|
||||
})
|
||||
}
|
||||
|
||||
async findAll(): Promise<SkillEntity[]> {
|
||||
return await this.skillRepository.find({
|
||||
relations: ['category', 'rank', 'level']
|
||||
});
|
||||
}
|
||||
|
||||
async create(skill: SkillDto): Promise<SkillDto> {
|
||||
return await this.skillRepository.save(skill)
|
||||
}
|
||||
|
||||
async update(
|
||||
id: string,
|
||||
skillDto: SkillDto
|
||||
): Promise<SkillDto> {
|
||||
const skillEntity: SkillEntity = await this.skillRepository.findOneBy({ id })
|
||||
const skillEntityUpdated = Object.assign(skillEntity, skillDto)
|
||||
|
||||
return await this.skillRepository.save(skillEntityUpdated)
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<DeleteResult> {
|
||||
return await this.skillRepository.delete({ id })
|
||||
}
|
||||
|
||||
async getLevels(): Promise<SkillLevelEntity[]> {
|
||||
const levels = await this.skillLevelRepository.find()
|
||||
console.log(levels);
|
||||
return levels
|
||||
}
|
||||
|
||||
async getRanks(): Promise<SkillRankEntity[]> {
|
||||
return await this.skillRankRepository.find()
|
||||
}
|
||||
}
|
||||
10
api/src/status/status.entity.ts
Normal file
10
api/src/status/status.entity.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
|
||||
|
||||
@Entity({ name: 'statuses' })
|
||||
export class StatusEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
}
|
||||
24
api/test/app.e2e-spec.ts
Normal file
24
api/test/app.e2e-spec.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import * as request from 'supertest';
|
||||
import { AppModule } from './../src/app.module';
|
||||
|
||||
describe('AppController (e2e)', () => {
|
||||
let app: INestApplication;
|
||||
|
||||
beforeEach(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
await app.init();
|
||||
});
|
||||
|
||||
it('/ (GET)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect('Hello World!');
|
||||
});
|
||||
});
|
||||
9
api/test/jest-e2e.json
Normal file
9
api/test/jest-e2e.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"moduleFileExtensions": ["js", "json", "ts"],
|
||||
"rootDir": ".",
|
||||
"testEnvironment": "node",
|
||||
"testRegex": ".e2e-spec.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
}
|
||||
}
|
||||
4
api/tsconfig.build.json
Normal file
4
api/tsconfig.build.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
||||
}
|
||||
21
api/tsconfig.json
Normal file
21
api/tsconfig.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": false,
|
||||
"noImplicitAny": false,
|
||||
"strictBindCallApply": false,
|
||||
"forceConsistentCasingInFileNames": false,
|
||||
"noFallthroughCasesInSwitch": false
|
||||
}
|
||||
}
|
||||
6
client/.env
Normal file
6
client/.env
Normal file
@@ -0,0 +1,6 @@
|
||||
VITE_API_URL=http://localhost:3000
|
||||
# VITE_API_URL=https://flying-api-dev.greensea-e83e7646.centralus.azurecontainerapps.io/
|
||||
VITE_CLIENT_ID=b9beb879-aea1-4434-af04-7ab233021b48
|
||||
VITE_TENANT_ID=7fdd758c-7277-4d47-bf0a-0b8b164ef2a6
|
||||
VITE_REDIRECT_URL=http://localhost:8080
|
||||
VITE_ISSUER_URI="https://7fdd758c-7277-4d47-bf0a-0b8b164ef2a6.ciamlogin.com/7fdd758c-7277-4d47-bf0a-0b8b164ef2a6/v2.0/"
|
||||
24
client/.gitignore
vendored
Normal file
24
client/.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
1
client/README.md
Normal file
1
client/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# APP
|
||||
28
client/eslint.config.js
Normal file
28
client/eslint.config.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
|
||||
export default tseslint.config(
|
||||
{ ignores: ['dist'] },
|
||||
{
|
||||
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
plugins: {
|
||||
'react-hooks': reactHooks,
|
||||
'react-refresh': reactRefresh,
|
||||
},
|
||||
rules: {
|
||||
...reactHooks.configs.recommended.rules,
|
||||
'react-refresh/only-export-components': [
|
||||
'warn',
|
||||
{ allowConstantExport: true },
|
||||
],
|
||||
},
|
||||
},
|
||||
)
|
||||
13
client/index.html
Normal file
13
client/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Noah Spannbauer</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
47
client/package.json
Normal file
47
client/package.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "app",
|
||||
"private": true,
|
||||
"version": "1.2.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-svg-core": "^7.2.0",
|
||||
"@fortawesome/free-solid-svg-icons": "^7.2.0",
|
||||
"@fortawesome/react-fontawesome": "^3.3.1",
|
||||
"@microsoft/microsoft-graph-types": "^2.40.0",
|
||||
"@tailwindcss/typography": "^0.5.19",
|
||||
"@tailwindcss/vite": "^4.3.0",
|
||||
"@tanstack/react-table": "^8.21.3",
|
||||
"axios": "^1.16.1",
|
||||
"oidc-spa": "^10.2.3",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"react-hook-form": "^7.77.0",
|
||||
"react-router-dom": "^7.1.5",
|
||||
"tailwindcss": "^4.3.0",
|
||||
"typeorm-extension": "^3.9.0",
|
||||
"zod": "^4.4.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.19.0",
|
||||
"@types/react": "^19.0.8",
|
||||
"@types/react-dom": "^19.0.3",
|
||||
"@vitejs/plugin-react": "^4.3.4",
|
||||
"daisyui": "^5.5.20",
|
||||
"eslint": "^9.19.0",
|
||||
"eslint-plugin-react-hooks": "^5.0.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.18",
|
||||
"globals": "^15.14.0",
|
||||
"typescript": "~5.7.2",
|
||||
"typescript-eslint": "^8.22.0",
|
||||
"vite": "^6.1.0"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
BIN
client/public/noahspan-logo.png
Normal file
BIN
client/public/noahspan-logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
1
client/public/vite.svg
Normal file
1
client/public/vite.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
23
client/src/App.tsx
Normal file
23
client/src/App.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Route, Routes } from 'react-router-dom';
|
||||
import Profiles from './components/profiles/Profiles';
|
||||
import Experiences from './components/experiences/Experiences';
|
||||
import Projects from './components/projects/Projects';
|
||||
import SiteNav from './components/siteNav/SiteNav';
|
||||
import SkillsPage from './components/skillsPage/SkillsPage';
|
||||
|
||||
const App = () => {
|
||||
|
||||
return (
|
||||
<div className='bg-[#f5f5f5]' data-theme="lofi">
|
||||
<SiteNav />
|
||||
<Routes>
|
||||
<Route path='/' element={<Profiles />} />
|
||||
<Route path='/experiences' element={<Experiences />} />
|
||||
<Route path='/projects' element={<Projects />} />
|
||||
<Route path='/skills' element={<SkillsPage />} />
|
||||
</Routes>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default App;
|
||||
7
client/src/alert/Alert.interface.ts
Normal file
7
client/src/alert/Alert.interface.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export interface AlertProps {
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
closeIcon?: React.ReactNode;
|
||||
onClose?: () => void;
|
||||
severity: 'info' | 'error' | 'success' | 'warning';
|
||||
}
|
||||
44
client/src/alert/Alert.tsx
Normal file
44
client/src/alert/Alert.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { AlertProps } from "./AlertProps.interface";
|
||||
import { faCircleCheck, faCircleInfo, faCircleXmark, faTriangleExclamation, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||
|
||||
const Alert = ({
|
||||
children,
|
||||
className,
|
||||
closeIcon,
|
||||
severity,
|
||||
onClose,
|
||||
...rest
|
||||
}: AlertProps) => {
|
||||
const severityVariants = {
|
||||
info: 'alert-info',
|
||||
error: 'alert-error',
|
||||
success: 'alert-success',
|
||||
warning: 'alert-warning'
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
role='alert'
|
||||
className={`alert ${severity ? severityVariants[severity] : ''} ${className ? className : ''}`}
|
||||
{...rest}
|
||||
>
|
||||
<span>
|
||||
{severity === 'info' && <FontAwesomeIcon icon={faCircleInfo} />}
|
||||
{severity === 'error' && <FontAwesomeIcon icon={faCircleXmark} />}
|
||||
{severity === 'success' && (
|
||||
<FontAwesomeIcon icon={faCircleCheck} />
|
||||
)}
|
||||
{severity === 'warning' && (
|
||||
<FontAwesomeIcon icon={faTriangleExclamation} />
|
||||
)}
|
||||
</span>
|
||||
<span>{children}</span>
|
||||
{closeIcon && <button className='btn' onClick={onClose}>{<FontAwesomeIcon icon={faXmark} />}</button>}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Alert;
|
||||
1
client/src/assets/react.svg
Normal file
1
client/src/assets/react.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
159
client/src/components/SkillCategoryForm/SkillCategoryForm.tsx
Normal file
159
client/src/components/SkillCategoryForm/SkillCategoryForm.tsx
Normal file
@@ -0,0 +1,159 @@
|
||||
import { useEffect, useReducer } from "react";
|
||||
import { SkillCategoryFormProps } from './SkillCategoryFormProps.interface'
|
||||
import { Controller, FormProvider, useForm } from "react-hook-form";
|
||||
import { useBreakpoints } from "../../hooks/breakpoints/UseBreakpoints";
|
||||
import { FormMode } from "../../enums/formMode";
|
||||
import { initialState, reducer } from "./reducer";
|
||||
import httpClient from "../../httpClient/httpClient";
|
||||
import { AxiosError, AxiosResponse } from "axios";
|
||||
import { ScreenSize } from "../../enums/screenSize";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faSave, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||
|
||||
const SkillCategoryForm = ({ isDrawerOpen, mode, onOpenClose, categoryId }: SkillCategoryFormProps) => {
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
const defaultValues = {
|
||||
name: ''
|
||||
}
|
||||
const methods = useForm({
|
||||
defaultValues: defaultValues
|
||||
})
|
||||
const { screenSize } = useBreakpoints();
|
||||
|
||||
const onCancel = () => {
|
||||
methods.reset(defaultValues);
|
||||
dispatch({ type: 'SET_IS_DISABLED', payload: false });
|
||||
onOpenClose(FormMode.CANCEL)
|
||||
}
|
||||
|
||||
const onSubmit = async (data: unknown) => {
|
||||
try {
|
||||
dispatch({ type: 'SET_IS_LOADING', payload: true })
|
||||
|
||||
if (!categoryId) {
|
||||
await httpClient.post(`api/skill-categories`, data);
|
||||
} else {
|
||||
await httpClient.put(`api/skill-categories`)
|
||||
}
|
||||
|
||||
methods.reset(defaultValues);
|
||||
dispatch({ type: 'SET_IS_DISABLED', payload: false })
|
||||
onOpenClose(FormMode.CANCEL)
|
||||
} catch (error) {
|
||||
const axiosError = error as AxiosError;
|
||||
|
||||
dispatch({ type: 'SET_ERROR', payload: axiosError.message })
|
||||
} finally {
|
||||
dispatch({ type: 'SET_IS_LOADING', payload: false })
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (mode === FormMode.VIEW) {
|
||||
dispatch({ type: 'SET_IS_DISABLED', payload: true })
|
||||
}
|
||||
}, [mode])
|
||||
|
||||
useEffect(() => {
|
||||
const getSkillCategory = async () => {
|
||||
try {
|
||||
dispatch({ type: 'SET_IS_LOADING', payload: true });
|
||||
|
||||
const response: AxiosResponse = await httpClient.get(
|
||||
`api/skill-categories/${categoryId}`
|
||||
);
|
||||
const category = response.data
|
||||
|
||||
methods.reset(category)
|
||||
} catch (error) {
|
||||
const axiosError = error as AxiosError;
|
||||
|
||||
dispatch({ type: 'SET_ERROR', payload: axiosError.message });
|
||||
} finally {
|
||||
dispatch({ type: 'SET_IS_LOADING', payload: false})
|
||||
}
|
||||
}
|
||||
|
||||
if (categoryId && isDrawerOpen) {
|
||||
getSkillCategory()
|
||||
}
|
||||
}, [categoryId])
|
||||
|
||||
return (
|
||||
<div className='drawer drawer-end'>
|
||||
<input type='checkbox' className='drawer-toggle' onChange={() => {}} checked={isDrawerOpen} />
|
||||
<div className='drawer-side'>
|
||||
<label
|
||||
htmlFor='my-drawer-1'
|
||||
aria-label='close-sidebar'
|
||||
className='drawer-overlay'
|
||||
></label>
|
||||
<div className={`menu bg-base-100 text-base-content min-h-full p-4 ${screenSize === ScreenSize.SM ? 'w-full' : screenSize === ScreenSize.MD ? 'w-[66%]' : 'w-[33%]'}`}>
|
||||
<FormProvider {...methods}>
|
||||
<form className='prose max-w-none' onSubmit={methods.handleSubmit(onSubmit)} style={{ paddingBottom: '50px' }}>
|
||||
<div className='grid grid-cols-12 gap-3'>
|
||||
<div className="col-span-10">
|
||||
<h2 className="mt-0 mb-0 self-center">
|
||||
{`${mode.toString().toLowerCase().charAt(0).toUpperCase() + mode.toString().slice(1).toLowerCase()} Skill Category`}
|
||||
</h2>
|
||||
</div>
|
||||
<div className="col-span-2 justify-self-end self-center">
|
||||
<button className="btn btn-ghost" onClick={onCancel}>
|
||||
<FontAwesomeIcon icon={faXmark} />
|
||||
</button>
|
||||
</div>
|
||||
<div className='col-span-3 self-center'>
|
||||
<span>Name *</span>
|
||||
</div>
|
||||
<div className='col-span-9'>
|
||||
<Controller
|
||||
name="name"
|
||||
control={methods.control}
|
||||
rules={{ required: 'A skill name is required' }}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<input
|
||||
type='text'
|
||||
className='input w-full'
|
||||
disabled={state.isDisabled}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className='col-span-12 justify-self-end self-center'>
|
||||
<button
|
||||
className='btn'
|
||||
disabled={
|
||||
state.isDisabled && mode.toString() !== FormMode.VIEW
|
||||
? state.isDisabled
|
||||
: false
|
||||
}
|
||||
onClick={onCancel}
|
||||
data-testid="skill-category-cancel-button"
|
||||
>
|
||||
<FontAwesomeIcon icon={faXmark} />
|
||||
{mode.toString() !== FormMode.VIEW ? 'Cancel' : 'Close'}
|
||||
</button>
|
||||
{mode.toString() !== FormMode.VIEW && (
|
||||
<button
|
||||
className='btn btn-primary ml-2.5'
|
||||
disabled={state.isDisabled}
|
||||
type="submit"
|
||||
data-testid="skill-category-save-button"
|
||||
>
|
||||
<FontAwesomeIcon icon={faSave} />
|
||||
Save
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</FormProvider>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
};
|
||||
|
||||
export default SkillCategoryForm;
|
||||
@@ -0,0 +1,8 @@
|
||||
import { FormMode } from "../../enums/formMode";
|
||||
|
||||
export interface SkillCategoryFormProps {
|
||||
categoryId: string | undefined;
|
||||
isDrawerOpen: boolean;
|
||||
mode: FormMode;
|
||||
onOpenClose: (mode: FormMode) => void;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export interface SkillCategoryFormState {
|
||||
error: string | undefined;
|
||||
isDisabled: boolean;
|
||||
isLoading: boolean;
|
||||
}
|
||||
42
client/src/components/SkillCategoryForm/reducer.ts
Normal file
42
client/src/components/SkillCategoryForm/reducer.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { SkillFormState } from '../SkillForm/SkillFormState.interface';
|
||||
import { SkillCategoryFormState } from './SkillCategoryFormState.interface';
|
||||
|
||||
type Action =
|
||||
| { type: 'SET_ERROR'; payload: string | undefined }
|
||||
| { type: 'SET_IS_DISABLED'; payload: boolean }
|
||||
| { type: 'SET_IS_LOADING'; payload: boolean }
|
||||
|
||||
export const initialState: SkillCategoryFormState = {
|
||||
error: undefined,
|
||||
isDisabled: false,
|
||||
isLoading: true
|
||||
}
|
||||
|
||||
export const reducer = (
|
||||
state: SkillCategoryFormState,
|
||||
action: Action
|
||||
): SkillCategoryFormState => {
|
||||
switch (action.type) {
|
||||
case 'SET_ERROR': {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload
|
||||
}
|
||||
}
|
||||
case 'SET_IS_DISABLED': {
|
||||
return {
|
||||
...state,
|
||||
isDisabled: action.payload
|
||||
}
|
||||
}
|
||||
case 'SET_IS_LOADING': {
|
||||
return {
|
||||
...state,
|
||||
isLoading: action.payload
|
||||
}
|
||||
}
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
297
client/src/components/SkillForm/SkillForm.tsx
Normal file
297
client/src/components/SkillForm/SkillForm.tsx
Normal file
@@ -0,0 +1,297 @@
|
||||
import { useEffect, useReducer } from 'react';
|
||||
import { useForm, Controller, FormProvider } from 'react-hook-form';
|
||||
import { initialState, reducer } from './reducer';
|
||||
import { SkillFormProps } from './SkillFormProps.interface';
|
||||
import { FormMode } from '../../enums/formMode';
|
||||
import httpClient from '../../httpClient/httpClient';
|
||||
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faSave, faXmark } from '@fortawesome/free-solid-svg-icons';
|
||||
import { ScreenSize } from '../../enums/screenSize';
|
||||
import { useBreakpoints } from '../../hooks/breakpoints/UseBreakpoints';
|
||||
|
||||
const SkillForm = ({ isDrawerOpen, mode, onOpenClose, skillId }: SkillFormProps) => {
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
const defaultValues = {
|
||||
name: '',
|
||||
categoryId: '',
|
||||
levelId: '',
|
||||
rankId: ''
|
||||
}
|
||||
const methods = useForm({
|
||||
defaultValues: defaultValues
|
||||
});
|
||||
const { screenSize } = useBreakpoints();
|
||||
|
||||
const onCancel = () => {
|
||||
methods.reset(defaultValues);
|
||||
dispatch({ type: 'SET_IS_DISABLED', payload: false });
|
||||
onOpenClose(FormMode.CANCEL);
|
||||
};
|
||||
|
||||
const onSubmit = async (data: unknown) => {
|
||||
try {
|
||||
dispatch({ type: 'SET_IS_LOADING', payload: true });
|
||||
console.log(data)
|
||||
if (!skillId) {
|
||||
await httpClient.post(`api/skills`, data);
|
||||
} else {
|
||||
await httpClient.put(`api/skills/skill/${skillId}`, data);
|
||||
}
|
||||
|
||||
methods.reset(defaultValues);
|
||||
dispatch({ type: 'SET_IS_DISABLED', payload: false });
|
||||
onOpenClose(FormMode.CANCEL);
|
||||
} catch (error) {
|
||||
const axiosError = error as AxiosError;
|
||||
console.log(axiosError)
|
||||
dispatch({ type: 'SET_ERROR', payload: axiosError.message });
|
||||
} finally {
|
||||
dispatch({ type: 'SET_IS_LOADING', payload: false });
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (mode === FormMode.VIEW) {
|
||||
dispatch({ type: 'SET_IS_DISABLED', payload: true });
|
||||
}
|
||||
}, [mode]);
|
||||
|
||||
useEffect(() => {
|
||||
const getSkill = async () => {
|
||||
try {
|
||||
dispatch({ type: 'SET_IS_LOADING', payload: true });
|
||||
|
||||
const skillResponse: AxiosResponse = await httpClient.get(
|
||||
`api/skills/${skillId}`
|
||||
);
|
||||
const skill = skillResponse.data;
|
||||
|
||||
methods.reset(skill);
|
||||
} catch (error) {
|
||||
const axiosError = error as AxiosError;
|
||||
console.log(axiosError)
|
||||
dispatch({ type: 'SET_ERROR', payload: axiosError.message });
|
||||
} finally {
|
||||
dispatch({ type: 'SET_IS_LOADING', payload: false });
|
||||
}
|
||||
};
|
||||
|
||||
if (skillId && isDrawerOpen) {
|
||||
getSkill();
|
||||
}
|
||||
}, [skillId]);
|
||||
|
||||
useEffect(() => {
|
||||
const getOptions = async () => {
|
||||
try {
|
||||
const skillCategoryResponse: AxiosResponse = await httpClient.get(
|
||||
`api/skill-categories`
|
||||
)
|
||||
const newSkillCategoryOptions = skillCategoryResponse.data.map((category: any) => {
|
||||
return {
|
||||
label: category.name,
|
||||
value: category.id
|
||||
}
|
||||
})
|
||||
const skillLevelResponse: AxiosResponse = await httpClient.get(
|
||||
`api/skill-levels`
|
||||
);
|
||||
const newSkillLevelOptions = skillLevelResponse.data.map((level: any) => {
|
||||
return {
|
||||
label: level.name,
|
||||
value: level.id
|
||||
}
|
||||
});
|
||||
const skillRankResponse: AxiosResponse = await httpClient.get(
|
||||
`api/skill-ranks`
|
||||
);
|
||||
const newSkillRankOptions = skillRankResponse.data.map((rank: any) => {
|
||||
return {
|
||||
label: rank.name,
|
||||
value: rank.id
|
||||
}
|
||||
});
|
||||
|
||||
newSkillCategoryOptions.unshift({
|
||||
label: '',
|
||||
value: '',
|
||||
})
|
||||
|
||||
newSkillLevelOptions.unshift({
|
||||
label: '',
|
||||
value: '',
|
||||
})
|
||||
|
||||
newSkillRankOptions.unshift({
|
||||
label: '',
|
||||
value: '',
|
||||
})
|
||||
|
||||
dispatch({ type: 'SET_OPTIONS', payload: { categoryOptions: newSkillCategoryOptions, levelOptions: newSkillLevelOptions, rankOptions: newSkillRankOptions }})
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (isDrawerOpen) {
|
||||
getOptions()
|
||||
}
|
||||
}, [isDrawerOpen])
|
||||
|
||||
return (
|
||||
<div className='drawer drawer-end'>
|
||||
<input type='checkbox' className='drawer-toggle' onChange={() => {}} checked={isDrawerOpen} />
|
||||
<div className='drawer-side'>
|
||||
<label
|
||||
htmlFor='my-drawer-1'
|
||||
aria-label='close-sidebar'
|
||||
className='drawer-overlay'
|
||||
></label>
|
||||
<div className={`menu bg-base-100 text-base-content min-h-full p-4 ${screenSize === ScreenSize.SM ? 'w-full' : screenSize === ScreenSize.MD ? 'w-[66%]' : 'w-[33%]'}`}>
|
||||
<FormProvider {...methods}>
|
||||
<form className='prose max-w-none' onSubmit={methods.handleSubmit(onSubmit)} style={{ paddingBottom: '50px' }}>
|
||||
<div className='grid grid-cols-12 gap-3'>
|
||||
<div className="col-span-10">
|
||||
<h2 className="mt-0 mb-0 self-center">
|
||||
{`${mode.toString().toLowerCase().charAt(0).toUpperCase() + mode.toString().slice(1).toLowerCase()} Skill`}
|
||||
</h2>
|
||||
</div>
|
||||
<div className="col-span-2 justify-self-end self-center">
|
||||
<button className="btn btn-ghost" onClick={onCancel}>
|
||||
<FontAwesomeIcon icon={faXmark} />
|
||||
</button>
|
||||
</div>
|
||||
<div className='col-span-3 self-center'>
|
||||
<span>Name *</span>
|
||||
</div>
|
||||
<div className='col-span-9'>
|
||||
<Controller
|
||||
name="name"
|
||||
control={methods.control}
|
||||
rules={{ required: 'A skill name is required' }}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<input
|
||||
type='text'
|
||||
className='input w-full'
|
||||
disabled={state.isDisabled}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className='col-span-3 self-center'>
|
||||
<span>Cateogry</span>
|
||||
</div>
|
||||
<div className='col-span-9'>
|
||||
<Controller
|
||||
name="categoryId"
|
||||
control={methods.control}
|
||||
render={({ field: { onChange, value } }) => {
|
||||
return (
|
||||
<select
|
||||
className='select w-full'
|
||||
aria-labelledby='category'
|
||||
disabled={state.isDisabled}
|
||||
onChange={onChange}
|
||||
value={[value]}
|
||||
>
|
||||
{state.categoryOptions?.map((categoryOption: { label: string, value: string }) => {
|
||||
return (
|
||||
<option value={categoryOption.value}>{categoryOption.label}</option>
|
||||
)
|
||||
})}
|
||||
</select>
|
||||
)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className='col-span-3 self-center'>
|
||||
<span>Level</span>
|
||||
</div>
|
||||
<div className='col-span-9'>
|
||||
<Controller
|
||||
name="levelId"
|
||||
control={methods.control}
|
||||
render={({ field: { onChange, value } }) => {
|
||||
return (
|
||||
<select
|
||||
className='select w-full'
|
||||
aria-labelledby='levels'
|
||||
disabled={state.isDisabled}
|
||||
onChange={onChange}
|
||||
value={[value]}
|
||||
>
|
||||
{state.levelOptions?.map((levelOption: { label: string, value: string }) => {
|
||||
return (
|
||||
<option value={levelOption.value}>{levelOption.label}</option>
|
||||
)
|
||||
})}
|
||||
</select>
|
||||
)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className='col-span-3 self-center'>
|
||||
<span>Rank</span>
|
||||
</div>
|
||||
<div className='col-span-9'>
|
||||
<Controller
|
||||
name="rankId"
|
||||
control={methods.control}
|
||||
render={({ field: { onChange, value } }) => {
|
||||
return (
|
||||
<select
|
||||
className='select w-full'
|
||||
aria-labelledby='rank'
|
||||
disabled={state.isDisabled}
|
||||
onChange={onChange}
|
||||
value={[value]}
|
||||
>
|
||||
{state.rankOptions?.map((rankOption: { label: string, value: string }) => {
|
||||
return (
|
||||
<option value={rankOption.value}>{rankOption.label}</option>
|
||||
)
|
||||
})}
|
||||
</select>
|
||||
)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className='col-span-12 justify-self-end self-center'>
|
||||
<button
|
||||
className='btn'
|
||||
disabled={
|
||||
state.isDisabled && mode.toString() !== FormMode.VIEW
|
||||
? state.isDisabled
|
||||
: false
|
||||
}
|
||||
onClick={onCancel}
|
||||
data-testid="skill-cancel-button"
|
||||
>
|
||||
<FontAwesomeIcon icon={faXmark} />
|
||||
{mode.toString() !== FormMode.VIEW ? 'Cancel' : 'Close'}
|
||||
</button>
|
||||
{mode.toString() !== FormMode.VIEW && (
|
||||
<button
|
||||
className='btn btn-primary ml-2.5'
|
||||
disabled={state.isDisabled}
|
||||
type="submit"
|
||||
data-testid="skill-save-button"
|
||||
>
|
||||
<FontAwesomeIcon icon={faSave} />
|
||||
Save
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</FormProvider>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default SkillForm;
|
||||
@@ -0,0 +1,8 @@
|
||||
import { FormMode } from "../../enums/formMode";
|
||||
|
||||
export interface SkillFormProps {
|
||||
skillId?: string;
|
||||
isDrawerOpen: boolean;
|
||||
mode: FormMode;
|
||||
onOpenClose: (mode: FormMode) => void;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export interface SkillFormState {
|
||||
error: string | undefined;
|
||||
isDisabled: boolean;
|
||||
isLoading: boolean;
|
||||
categoryOptions: { label: string; value: string }[];
|
||||
levelOptions: { label: string; value: string }[];
|
||||
rankOptions: { label: string; value: string }[];
|
||||
}
|
||||
53
client/src/components/SkillForm/reducer.ts
Normal file
53
client/src/components/SkillForm/reducer.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { SkillFormState } from "./SkillFormState.interface"
|
||||
|
||||
type Action =
|
||||
| { type: 'SET_ERROR'; payload: string | undefined }
|
||||
| { type: 'SET_IS_DISABLED'; payload: boolean }
|
||||
| { type: 'SET_IS_LOADING'; payload: boolean }
|
||||
| { type: 'SET_OPTIONS'; payload: { categoryOptions: { label: string, value: string; }[], levelOptions: { label: string, value: string; }[], rankOptions: { label: string, value: string; }[] }}
|
||||
|
||||
export const initialState: SkillFormState = {
|
||||
error: undefined,
|
||||
isDisabled: false,
|
||||
isLoading: true,
|
||||
categoryOptions: [],
|
||||
levelOptions: [],
|
||||
rankOptions: [],
|
||||
};
|
||||
|
||||
export const reducer = (
|
||||
state: SkillFormState,
|
||||
action: Action
|
||||
): SkillFormState => {
|
||||
switch (action.type) {
|
||||
case 'SET_ERROR': {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload
|
||||
};
|
||||
}
|
||||
case 'SET_IS_DISABLED': {
|
||||
return {
|
||||
...state,
|
||||
isDisabled: action.payload
|
||||
};
|
||||
}
|
||||
case 'SET_IS_LOADING': {
|
||||
return {
|
||||
...state,
|
||||
isLoading: action.payload
|
||||
};
|
||||
}
|
||||
case 'SET_OPTIONS': {
|
||||
return {
|
||||
...state,
|
||||
categoryOptions: action.payload.categoryOptions,
|
||||
levelOptions: action.payload.levelOptions,
|
||||
rankOptions: action.payload.rankOptions
|
||||
}
|
||||
}
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
};
|
||||
62
client/src/components/actionMenu/ActionMenu.tsx
Normal file
62
client/src/components/actionMenu/ActionMenu.tsx
Normal file
@@ -0,0 +1,62 @@
|
||||
import { useState } from 'react';
|
||||
import { ActionMenuProps } from './ActionMenuProps.interface';
|
||||
import {
|
||||
Icon,
|
||||
IconButton,
|
||||
IconName,
|
||||
ListItemIcon,
|
||||
ListItemText,
|
||||
Menu,
|
||||
MenuItem,
|
||||
} from '@noahspan/noahspan-components';
|
||||
import { FormMode } from '../../enums/formMode';
|
||||
|
||||
const ActionMenu = ({ id, onDelete, onOpenCloseForm }: ActionMenuProps) => {
|
||||
const [anchorElAction, setAnchorElAction] = useState<null | HTMLElement>(
|
||||
null
|
||||
);
|
||||
|
||||
const onOpenActionMenu = (event: React.MouseEvent<HTMLElement>) => {
|
||||
setAnchorElAction(event.currentTarget);
|
||||
};
|
||||
|
||||
const onCloseActionMenu = () => {
|
||||
setAnchorElAction(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<IconButton onClick={onOpenActionMenu}>
|
||||
<Icon iconName={IconName.ELLIPSIS_VERTICAL} size="sm" />
|
||||
</IconButton>
|
||||
<Menu
|
||||
anchorEl={anchorElAction}
|
||||
keepMounted
|
||||
open={Boolean(anchorElAction)}
|
||||
onClose={onCloseActionMenu}
|
||||
>
|
||||
<MenuItem onClick={() => onOpenCloseForm(FormMode.EDIT, id)}>
|
||||
<ListItemIcon>
|
||||
<Icon iconName={IconName.PEN} size="lg" />
|
||||
</ListItemIcon>
|
||||
<ListItemText>Edit</ListItemText>
|
||||
</MenuItem>
|
||||
<MenuItem onClick={() => onOpenCloseForm(FormMode.VIEW, id)}>
|
||||
<ListItemIcon>
|
||||
<Icon iconName={IconName.EYE} size="lg" />
|
||||
</ListItemIcon>
|
||||
<ListItemText>View</ListItemText>
|
||||
</MenuItem>
|
||||
<hr className="my-3" />
|
||||
<MenuItem onClick={() => onDelete(id)}>
|
||||
<ListItemIcon>
|
||||
<Icon iconName={IconName.TRASH} size="lg" />
|
||||
</ListItemIcon>
|
||||
<ListItemText>Delete</ListItemText>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ActionMenu;
|
||||
@@ -0,0 +1,7 @@
|
||||
import { FormMode } from '../../enums/formMode';
|
||||
|
||||
export interface ActionMenuProps {
|
||||
id: string;
|
||||
onDelete: (entryId: string) => void;
|
||||
onOpenCloseForm: (formMode: FormMode, id: string) => void;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import {
|
||||
Button,
|
||||
Dialog,
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
DialogContentText,
|
||||
DialogTitle,
|
||||
Icon,
|
||||
IconName,
|
||||
Spinner
|
||||
} from '@noahspan/noahspan-components';
|
||||
import { ConfirmationDialogProps } from './ConfirmationDialogProps.interface';
|
||||
|
||||
const ConfirmationDialog = ({
|
||||
contentText,
|
||||
isLoading,
|
||||
isOpen,
|
||||
onCancel,
|
||||
onConfirm,
|
||||
title
|
||||
}: ConfirmationDialogProps) => {
|
||||
return (
|
||||
<Dialog
|
||||
onClose={onCancel}
|
||||
open={isOpen}
|
||||
sx={{
|
||||
'& .MuiDialog-paper': { width: '2000px' }
|
||||
}}
|
||||
>
|
||||
<DialogTitle>{title}</DialogTitle>
|
||||
<DialogContent sx={{ textAlign: 'center' }}>
|
||||
{!isLoading && <DialogContentText>{contentText}</DialogContentText>}
|
||||
{isLoading && <Spinner />}
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={onCancel} variant="outlined" startIcon={<Icon iconName={IconName.XMARK} />}>
|
||||
No
|
||||
</Button>
|
||||
<Button
|
||||
onClick={onConfirm}
|
||||
variant="contained"
|
||||
startIcon={<Icon iconName={IconName.CIRCLE_CHECK}/>}
|
||||
>
|
||||
Yes
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default ConfirmationDialog;
|
||||
@@ -0,0 +1,8 @@
|
||||
export interface ConfirmationDialogProps {
|
||||
contentText: string;
|
||||
isLoading: boolean;
|
||||
isOpen: boolean;
|
||||
onCancel: () => void;
|
||||
onConfirm: () => void;
|
||||
title: string;
|
||||
}
|
||||
354
client/src/components/experienceForm/ExperienceForm.tsx
Normal file
354
client/src/components/experienceForm/ExperienceForm.tsx
Normal file
@@ -0,0 +1,354 @@
|
||||
import { useEffect, useReducer } from 'react';
|
||||
import { useForm, Controller, FormProvider } from 'react-hook-form';
|
||||
import { initialState, reducer } from './reducer';
|
||||
import { ExperienceFormProps } from './ExperienceFormProps.interface';
|
||||
import { FormMode } from '../../enums/formMode';
|
||||
import httpClient from '../../httpClient/httpClient';
|
||||
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faSave, faXmark } from '@fortawesome/free-solid-svg-icons';
|
||||
import { ScreenSize } from '../../enums/screenSize';
|
||||
import { useBreakpoints } from '../../hooks/breakpoints/UseBreakpoints';
|
||||
import { Profile } from '../profiles/Profile.interface';
|
||||
import { useProfiles } from '../../hooks/profiles/UseProfiles';
|
||||
import { useAppContext } from '../../hooks/appContext/UseAppContext';
|
||||
import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from '@headlessui/react';
|
||||
import { useSkills } from '../../hooks/skills/UseSkills';
|
||||
|
||||
const ExperienceForm = ({ isDrawerOpen, mode, onOpenClose, experienceId }: ExperienceFormProps) => {
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
const appContext = useAppContext();
|
||||
const { profiles } = useProfiles();
|
||||
const { skills } = useSkills();
|
||||
const defaultValues = {
|
||||
profileId: '',
|
||||
companyName: '',
|
||||
companyGeneric: '',
|
||||
title: '',
|
||||
startDate: '',
|
||||
endDate: '',
|
||||
skills: [],
|
||||
summary: '',
|
||||
statusId: 1,
|
||||
createdBy: '',
|
||||
updatedBy: ''
|
||||
}
|
||||
const methods = useForm({
|
||||
defaultValues: defaultValues
|
||||
});
|
||||
// const watchRepoName = methods.watch(['repoName'])
|
||||
const { screenSize } = useBreakpoints();
|
||||
|
||||
const onCancel = () => {
|
||||
methods.reset(defaultValues);
|
||||
dispatch({ type: 'SET_IS_DISABLED', payload: false });
|
||||
onOpenClose(FormMode.CANCEL);
|
||||
};
|
||||
|
||||
const onSubmit = async (data: any) => {
|
||||
try {
|
||||
dispatch({ type: 'SET_IS_LOADING', payload: true });
|
||||
|
||||
if (!experienceId) {
|
||||
const newData = {
|
||||
...data,
|
||||
createdBy: appContext.state.userProfile.userPrincipalName
|
||||
}
|
||||
await httpClient.post(`api/experiences`, newData);
|
||||
} else {
|
||||
const newData = {
|
||||
...data,
|
||||
updatedBy: appContext.state.userProfile.userPrincipalName
|
||||
}
|
||||
|
||||
await httpClient.put(`api/experiences/${experienceId}`, newData);
|
||||
}
|
||||
|
||||
methods.reset(defaultValues);
|
||||
dispatch({ type: 'SET_IS_DISABLED', payload: false });
|
||||
onOpenClose(FormMode.CANCEL);
|
||||
} catch (error) {
|
||||
const axiosError = error as AxiosError;
|
||||
console.log(axiosError)
|
||||
dispatch({ type: 'SET_ERROR', payload: axiosError.message });
|
||||
} finally {
|
||||
dispatch({ type: 'SET_IS_LOADING', payload: false });
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (mode === FormMode.VIEW) {
|
||||
dispatch({ type: 'SET_IS_DISABLED', payload: true });
|
||||
}
|
||||
}, [mode]);
|
||||
|
||||
useEffect(() => {
|
||||
const getExperience = async () => {
|
||||
try {
|
||||
dispatch({ type: 'SET_IS_LOADING', payload: true });
|
||||
|
||||
const response: AxiosResponse = await httpClient.get(
|
||||
`api/experiences/${experienceId}`
|
||||
);
|
||||
const experience = response.data;
|
||||
|
||||
methods.reset(experience);
|
||||
} catch (error) {
|
||||
const axiosError = error as AxiosError;
|
||||
console.log(axiosError)
|
||||
dispatch({ type: 'SET_ERROR', payload: axiosError.message });
|
||||
} finally {
|
||||
dispatch({ type: 'SET_IS_LOADING', payload: false });
|
||||
}
|
||||
};
|
||||
|
||||
if (experienceId && isDrawerOpen) {
|
||||
getExperience();
|
||||
}
|
||||
}, [experienceId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (profiles && FormMode.ADD) {
|
||||
const newProfileOptions = profiles
|
||||
|
||||
newProfileOptions.unshift({
|
||||
id: '',
|
||||
name: '',
|
||||
headline: '',
|
||||
summary: '',
|
||||
userId: '',
|
||||
experiences: [],
|
||||
skills: [],
|
||||
status: null
|
||||
})
|
||||
|
||||
dispatch({ type: 'SET_PROFILE_OPTIONS', payload: newProfileOptions });
|
||||
}
|
||||
}, [profiles]);
|
||||
|
||||
useEffect(() => {
|
||||
dispatch({ type: 'SET_SKILL_OPTIONS', payload: skills })
|
||||
}, [skills])
|
||||
|
||||
return (
|
||||
<div className='drawer drawer-end'>
|
||||
<input type='checkbox' className='drawer-toggle' onChange={() => {}} checked={isDrawerOpen} />
|
||||
<div className='drawer-side'>
|
||||
<label
|
||||
htmlFor='my-drawer-1'
|
||||
aria-label='close-sidebar'
|
||||
className='drawer-overlay'
|
||||
></label>
|
||||
<div className={`menu bg-base-100 text-base-content min-h-full p-4 ${screenSize === ScreenSize.SM ? 'w-full' : screenSize === ScreenSize.MD ? 'w-[66%]' : 'w-[33%]'}`}>
|
||||
<FormProvider {...methods}>
|
||||
<form className='prose max-w-none' onSubmit={methods.handleSubmit(onSubmit)} style={{ paddingBottom: '50px' }}>
|
||||
<div className='grid grid-cols-12 gap-3'>
|
||||
<div className="col-span-10">
|
||||
<h2 className="mt-0 mb-0 self-center">
|
||||
{`${mode.toString().toLowerCase().charAt(0).toUpperCase() + mode.toString().slice(1).toLowerCase()} Experience`}
|
||||
</h2>
|
||||
</div>
|
||||
<div className="col-span-2 justify-self-end self-center">
|
||||
<button className="btn btn-ghost" onClick={onCancel}>
|
||||
<FontAwesomeIcon icon={faXmark} />
|
||||
</button>
|
||||
</div>
|
||||
<div className={`col-span-3 self-center text-small after:content-['*'] after:text-danger after:ms-0.5`}>
|
||||
<span id='pilot'>Profile</span>
|
||||
</div>
|
||||
<div className='col-span-9 self-center'>
|
||||
<Controller
|
||||
name="profileId"
|
||||
control={methods.control}
|
||||
render={({ field: { onChange, value } }) => {
|
||||
return (
|
||||
<select
|
||||
className='select w-full'
|
||||
aria-labelledby='profile'
|
||||
disabled={state.isDisabled}
|
||||
onChange={onChange}
|
||||
value={[value]}
|
||||
>
|
||||
{state.profileOptions?.map((profileOption: Profile) => {
|
||||
return (
|
||||
<option value={profileOption.id}>{profileOption.name}</option>
|
||||
)
|
||||
})}
|
||||
</select>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className={`col-span-3 self-center after:content-['*'] after:ms-0.5`}>
|
||||
<span>Company Name</span>
|
||||
</div>
|
||||
<div className='col-span-9'>
|
||||
<Controller
|
||||
name="companyName"
|
||||
control={methods.control}
|
||||
rules={{ required: 'A company name is required' }}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<input
|
||||
type='text'
|
||||
className='input w-full'
|
||||
disabled={state.isDisabled}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className='col-span-3 self-center'>
|
||||
<span>Company Generic</span>
|
||||
</div>
|
||||
<div className='col-span-9'>
|
||||
<Controller
|
||||
name="companyGeneric"
|
||||
control={methods.control}
|
||||
rules={{ required: 'A generic company description is required' }}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<input
|
||||
type='text'
|
||||
className='input w-full'
|
||||
disabled={state.isDisabled}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className='col-span-3 self-center'>
|
||||
<span>Title</span>
|
||||
</div>
|
||||
<div className='col-span-9'>
|
||||
<Controller
|
||||
name='title'
|
||||
control={methods.control}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<input
|
||||
type='text'
|
||||
className='input w-full'
|
||||
disabled={state.isDisabled}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className='col-span-3 self-center'>
|
||||
<span>Start Date</span>
|
||||
</div>
|
||||
<div className='col-span-9'>
|
||||
<Controller
|
||||
name='startDate'
|
||||
control={methods.control}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<input
|
||||
type='text'
|
||||
className='input w-full'
|
||||
disabled={state.isDisabled}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className='col-span-3 self-center'>
|
||||
<span>End Date</span>
|
||||
</div>
|
||||
<div className='col-span-9'>
|
||||
<Controller
|
||||
name='endDate'
|
||||
control={methods.control}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<input
|
||||
type='text'
|
||||
className='input w-full'
|
||||
disabled={state.isDisabled}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className='col-span-3 self-center'>
|
||||
<span>Summary</span>
|
||||
</div>
|
||||
<div className='col-span-9'>
|
||||
<Controller
|
||||
name="summary"
|
||||
control={methods.control}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<input
|
||||
type='text'
|
||||
className='input w-full'
|
||||
disabled={state.isDisabled}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className={`col-span-3 self-center after:content-['*'] after:ms-0.5`}>
|
||||
<span>Skills</span>
|
||||
</div>
|
||||
<div className='col-span-9'>
|
||||
<Controller
|
||||
name="skills"
|
||||
control={methods.control}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
// <input
|
||||
// type='text'
|
||||
// className='input w-full'
|
||||
// disabled={state.isDisabled}
|
||||
// onChange={onChange}
|
||||
// value={value}
|
||||
// />
|
||||
<Listbox value={value} onChange={onChange}>
|
||||
<ListboxOptions anchor='bottom'>
|
||||
{state.skillOptions?.map((skill) => (
|
||||
<ListboxOption key={skill.id} value={skill.id}>
|
||||
{skill.name}
|
||||
</ListboxOption>
|
||||
))}
|
||||
</ListboxOptions>
|
||||
</Listbox>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className='col-span-12 justify-self-end self-center'>
|
||||
<button
|
||||
className='btn'
|
||||
disabled={
|
||||
state.isDisabled && mode.toString() !== FormMode.VIEW
|
||||
? state.isDisabled
|
||||
: false
|
||||
}
|
||||
onClick={onCancel}
|
||||
data-testid="experience-cancel-button"
|
||||
>
|
||||
<FontAwesomeIcon icon={faXmark} />
|
||||
{mode.toString() !== FormMode.VIEW ? 'Cancel' : 'Close'}
|
||||
</button>
|
||||
{mode.toString() !== FormMode.VIEW && (
|
||||
<button
|
||||
className='btn btn-primary ml-2.5'
|
||||
disabled={state.isDisabled}
|
||||
type="submit"
|
||||
data-testid="experience-save-button"
|
||||
>
|
||||
<FontAwesomeIcon icon={faSave} />
|
||||
Save
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</FormProvider>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ExperienceForm;
|
||||
@@ -0,0 +1,8 @@
|
||||
import { FormMode } from "../../enums/formMode";
|
||||
|
||||
export interface ExperienceFormProps {
|
||||
experienceId?: string;
|
||||
isDrawerOpen: boolean;
|
||||
mode: FormMode;
|
||||
onOpenClose: (mode: FormMode) => void;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Profile } from "../profiles/Profile.interface";
|
||||
import { Skill } from "../skills/Skill.interface";
|
||||
|
||||
export interface ExperienceFormState {
|
||||
error: string | undefined;
|
||||
isDisabled: boolean;
|
||||
isLoading: boolean;
|
||||
profileOptions: Profile[];
|
||||
skillOptions: Skill[] | undefined;
|
||||
}
|
||||
59
client/src/components/experienceForm/reducer.ts
Normal file
59
client/src/components/experienceForm/reducer.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { Profile } from "../profiles/Profile.interface";
|
||||
import { Skill } from "../skills/Skill.interface";
|
||||
import { ExperienceFormState } from "./ExperienceFormState.interface"
|
||||
|
||||
type Action =
|
||||
| { type: 'SET_ERROR'; payload: string | undefined }
|
||||
| { type: 'SET_IS_DISABLED'; payload: boolean }
|
||||
| { type: 'SET_IS_LOADING'; payload: boolean }
|
||||
| { type: 'SET_PROFILE_OPTIONS'; payload: Profile[] }
|
||||
| { type: 'SET_SKILL_OPTIONS'; payload: Skill[] | undefined };
|
||||
|
||||
export const initialState: ExperienceFormState = {
|
||||
error: undefined,
|
||||
isDisabled: false,
|
||||
isLoading: true,
|
||||
profileOptions: [],
|
||||
skillOptions: []
|
||||
};
|
||||
|
||||
export const reducer = (
|
||||
state: ExperienceFormState,
|
||||
action: Action
|
||||
): ExperienceFormState => {
|
||||
switch (action.type) {
|
||||
case 'SET_ERROR': {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload
|
||||
};
|
||||
}
|
||||
case 'SET_IS_DISABLED': {
|
||||
return {
|
||||
...state,
|
||||
isDisabled: action.payload
|
||||
};
|
||||
}
|
||||
case 'SET_IS_LOADING': {
|
||||
return {
|
||||
...state,
|
||||
isLoading: action.payload
|
||||
};
|
||||
}
|
||||
case 'SET_PROFILE_OPTIONS': {
|
||||
return {
|
||||
...state,
|
||||
profileOptions: action.payload
|
||||
}
|
||||
}
|
||||
case 'SET_SKILL_OPTIONS': {
|
||||
return {
|
||||
...state,
|
||||
skillOptions: action.payload
|
||||
}
|
||||
}
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
};
|
||||
18
client/src/components/experiences/Experience.interface.ts
Normal file
18
client/src/components/experiences/Experience.interface.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Status } from '../../interfaces/Status.interface';
|
||||
import { Profile } from '../profiles/Profile.interface';
|
||||
import { Skill } from "../skills/Skill.interface";
|
||||
|
||||
export interface Experience {
|
||||
id: string;
|
||||
profileId: string;
|
||||
companyName: string;
|
||||
companyGenericName: string;
|
||||
location: string;
|
||||
title: string;
|
||||
startDate: Date;
|
||||
endDate?: Date;
|
||||
summary?: string;
|
||||
skills: Skill[];
|
||||
profile: Profile;
|
||||
status: Status;
|
||||
}
|
||||
370
client/src/components/experiences/Experiences.tsx
Normal file
370
client/src/components/experiences/Experiences.tsx
Normal file
@@ -0,0 +1,370 @@
|
||||
import { Experience } from './Experience.interface';
|
||||
import { FormMode } from '../../enums/formMode';
|
||||
import { useEffect, useReducer } from 'react';
|
||||
import { initialState, reducer } from './reducer';
|
||||
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
||||
import httpClient from '../../httpClient/httpClient'
|
||||
import { useOidc } from '../../oidc';
|
||||
import { useBreakpoints } from "../../hooks/breakpoints/UseBreakpoints";
|
||||
import ExperienceForm from '../experienceForm/ExperienceForm';
|
||||
import ConfirmationDialog from '../confirmationDialog/ConfirmationDialog';
|
||||
import ActionMenu from '../actionMenu/ActionMenu';
|
||||
import { ScreenSize } from '../../enums/screenSize';
|
||||
import { faEllipsisVertical, faEye, faPen, faPlane, faPlus, faTrash } from '@fortawesome/free-solid-svg-icons';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { UserRole } from '../../enums/userRole';
|
||||
import { useUserRole } from '../../hooks/userRole/UseUserRole';
|
||||
import Alert from '../../alert/Alert';
|
||||
import { CellContext, ColumnDef, flexRender, getCoreRowModel, getPaginationRowModel, useReactTable } from '@tanstack/react-table';
|
||||
import { Profile } from '../profiles/Profile.interface';
|
||||
|
||||
interface ActionsProps {
|
||||
id: string;
|
||||
}
|
||||
|
||||
const Experiences = () => {
|
||||
const [state, dispatch] = useReducer(reducer, initialState)
|
||||
const { userRole } = useUserRole();
|
||||
const { screenSize } = useBreakpoints();
|
||||
const { isUserLoggedIn } = useOidc();
|
||||
const Actions = ({ id }: ActionsProps) => {
|
||||
return (
|
||||
<div className='dropdown dropdown-end'>
|
||||
<div tabIndex={0} role='button' className='btn btn-ghost'><FontAwesomeIcon icon={faEllipsisVertical} /></div>
|
||||
<ul tabIndex={-1} className="dropdown-content menu bg-base-100 rounded-box z-1 w-52 p-2 shadow-sm border border-base-300">
|
||||
{isUserLoggedIn && userRole === UserRole.WRITE &&
|
||||
<li><a onClick={() => onOpenCloseExperienceForm(FormMode.EDIT, id)}><FontAwesomeIcon icon={faPen} />Edit</a></li>
|
||||
}
|
||||
<li><a onClick={() => onOpenCloseExperienceForm(FormMode.VIEW, id)}><FontAwesomeIcon icon={faEye} />View</a></li>
|
||||
{isUserLoggedIn && userRole === UserRole.WRITE &&
|
||||
<li><a onClick={() => onDeleteExperience(id)}><FontAwesomeIcon icon={faTrash} />Delete</a></li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
const getExperiences = async (): Promise<Experience[]> => {
|
||||
try {
|
||||
const response: AxiosResponse = await httpClient.get(
|
||||
`api/experiences`,
|
||||
);
|
||||
const experiences: Experience[] = response.data;
|
||||
console.log(experiences)
|
||||
|
||||
return experiences;
|
||||
} catch (error) {
|
||||
const axiosError = error as AxiosError;
|
||||
|
||||
throw new Error(axiosError.message);
|
||||
}
|
||||
};
|
||||
|
||||
const onOpenCloseExperienceForm = (mode: FormMode, experienceId?: string) => {
|
||||
switch (mode) {
|
||||
case FormMode.ADD:
|
||||
case FormMode.EDIT:
|
||||
case FormMode.VIEW:
|
||||
dispatch({
|
||||
type: 'SET_OPEN_CLOSE_EXPERIENCE_FORM',
|
||||
payload: {
|
||||
formMode: mode,
|
||||
selectedExperienceId: experienceId,
|
||||
isFormOpen: true
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
case FormMode.CANCEL:
|
||||
dispatch({
|
||||
type: 'SET_OPEN_CLOSE_EXPERIENCE_FORM',
|
||||
payload: {
|
||||
formMode: mode,
|
||||
selectedExperienceId: undefined,
|
||||
isFormOpen: false
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const onDeleteExperience = (entryId: string) => {
|
||||
dispatch({
|
||||
type: 'SET_DELETE',
|
||||
payload: { isConfirmationDialogOpen: true, selectedExperienceId: entryId }
|
||||
});
|
||||
};
|
||||
|
||||
const onConfirmationDialogConfirm = async () => {
|
||||
try {
|
||||
dispatch({ type: 'SET_IS_CONFIRMATION_DIALOG_LOADING', payload: true });
|
||||
|
||||
await httpClient.delete(`api/experiences/${state.selectedExperienceId}`);
|
||||
|
||||
dispatch({
|
||||
type: 'SET_DELETE',
|
||||
payload: { isConfirmationDialogOpen: false, selectedExperienceId: undefined }
|
||||
});
|
||||
await getExperiences();
|
||||
} catch (error) {
|
||||
const axiosError = error as AxiosError;
|
||||
|
||||
dispatch({
|
||||
type: 'SET_ALERT',
|
||||
payload: { severity: 'error', message: `Loading of experiences failed with the following message: ${axiosError.message}` }
|
||||
});
|
||||
} finally {
|
||||
dispatch({ type: 'SET_IS_CONFIRMATION_DIALOG_LOADING', payload: false });
|
||||
}
|
||||
};
|
||||
|
||||
const onConfirmationDialogCancel = () => {
|
||||
dispatch({
|
||||
type: 'SET_DELETE',
|
||||
payload: { isConfirmationDialogOpen: false, selectedExperienceId: undefined }
|
||||
});
|
||||
};
|
||||
|
||||
const columns: ColumnDef<Experience>[]= [
|
||||
{
|
||||
id: 'profile',
|
||||
accessorKey: 'profile',
|
||||
header: 'Profile',
|
||||
cell: (info: CellContext<Experience, unknown>) => {
|
||||
const profile: any = info.getValue();
|
||||
|
||||
return profile.name
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'companyName',
|
||||
accessorKey: 'companyName',
|
||||
header: 'Company Name',
|
||||
},
|
||||
{
|
||||
id: 'companyGeneric',
|
||||
accessorKey: 'companyGeneric',
|
||||
header: 'Company Generic'
|
||||
},
|
||||
{
|
||||
id: 'title',
|
||||
accessorKey: 'title',
|
||||
header: 'Title'
|
||||
},
|
||||
{
|
||||
id: 'startDate',
|
||||
accessorKey: 'startDate',
|
||||
header: 'Start Date'
|
||||
},
|
||||
{
|
||||
id: 'endDate',
|
||||
accessorKey: 'endDate',
|
||||
header: 'End Date'
|
||||
},
|
||||
{
|
||||
id: 'summary',
|
||||
accessorKey: 'summary',
|
||||
header: 'Summary'
|
||||
},
|
||||
{
|
||||
id: 'status',
|
||||
accessorKey: 'status',
|
||||
header: 'Status',
|
||||
cell: (info: CellContext<Experience, unknown>) => {
|
||||
console.log(info.getValue())
|
||||
const status: any = info.getValue();
|
||||
console.log(status)
|
||||
return status.name
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: 'Actions',
|
||||
meta: {
|
||||
align: 'text-center',
|
||||
headerAlign: 'text-center'
|
||||
},
|
||||
cell: (info: CellContext<Experience, unknown>) => {
|
||||
return (
|
||||
<Actions id={info.row.original.id} />
|
||||
)
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
const table = useReactTable({
|
||||
data: state.experiences,
|
||||
columns: columns,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
getPaginationRowModel: getPaginationRowModel()
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const loadExperiences = async () => {
|
||||
try {
|
||||
dispatch({ type: 'SET_IS_LOADING', payload: true })
|
||||
const experiences = await getExperiences();
|
||||
|
||||
if (experiences.length > 0) {
|
||||
dispatch({ type: 'SET_EXPERIENCES', payload: experiences });
|
||||
|
||||
if (state.alert) {
|
||||
dispatch({ type: 'SET_ALERT', payload: undefined })
|
||||
}
|
||||
} else {
|
||||
dispatch({ type: 'SET_ALERT', payload: { severity: 'info', message: 'No experiences found.'}});
|
||||
}
|
||||
} catch (error) {
|
||||
dispatch({
|
||||
type: 'SET_ALERT',
|
||||
payload: { severity: 'error', message: `Loading of experiences failed with the following message: ${error}` }
|
||||
});
|
||||
} finally {
|
||||
dispatch({ type: 'SET_IS_LOADING', payload: false })
|
||||
}
|
||||
}
|
||||
|
||||
if (!state.isFormOpen || !state.isConfirmDialogOpen) {
|
||||
loadExperiences();
|
||||
}
|
||||
}, [state.isFormOpen, state.isConfirmDialogOpen]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={`${screenSize === ScreenSize.SM ? 'mr-4 ml-4' : 'mr-10 ml-10'}`}>
|
||||
<div className='grid grid-cols-12'>
|
||||
<div className='prose max-w-none col-span-6 mt-5 mb-5' >
|
||||
<h2>Experiences</h2>
|
||||
</div>
|
||||
<div className='col-span-6 justify-self-end self-center'>
|
||||
{!state.isLoading && userRole === UserRole.WRITE &&
|
||||
<button
|
||||
className='btn btn-primary'
|
||||
onClick={() => onOpenCloseExperienceForm(FormMode.ADD)}
|
||||
data-testid="skill-add-button"
|
||||
>
|
||||
<FontAwesomeIcon icon={faPlus} />
|
||||
Add Experience
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
{!state.isLoading && state.alert && (
|
||||
<div className='col-span-12'>
|
||||
<Alert
|
||||
className='mb-5'
|
||||
onClose={() =>
|
||||
dispatch({ type: 'SET_ALERT', payload: undefined })
|
||||
}
|
||||
severity={state.alert.severity}
|
||||
>
|
||||
{state.alert.message}
|
||||
</Alert>
|
||||
</div>
|
||||
)}
|
||||
{state.experiences.length > 0 && screenSize !== ScreenSize.SM &&
|
||||
<div className='col-span-12 p-5 bg-base-100 border border-base-100 rounded-lg'>
|
||||
<table className='table min-w-full h-auto table-auto w-full'>
|
||||
<thead className='[&>tr]:first:rounded-lg bg-base-200'>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<tr className='group/tr outline-solid outline-transparent data-[focus-visible=true]:z-10 data-[focus-visible=true]:outline-2 data-[focus-visible=true]:outline-focus data-[focus-visible=true]:outline-offset-2' key={headerGroup.id}>
|
||||
{headerGroup.headers.map((header) => {
|
||||
return (
|
||||
<th
|
||||
className={`${header.column.columnDef.meta?.headerAlign ? header.column.columnDef.meta?.headerAlign : ''} group/th px-3 h-10 align-middle bg-default-100 whitespace-nowrap text-foreground-500 text-tiny font-semibold rounded data-[sortable=true]:cursor-pointer data-[hover=true]:text-foreground-400 outline-solid outline-transparent data-[focus-visible=true]:z-10 data-[focus-visible=true]:outline-2 data-[focus-visible=true]:outline-focus data-[focus-visible=true]:outline-offset-2 text-start`}
|
||||
colSpan={header.colSpan}
|
||||
key={header.id}
|
||||
>
|
||||
{header.isPlaceholder ? null : (
|
||||
<div>
|
||||
{flexRender(
|
||||
header.column.columnDef.header,
|
||||
header.getContext()
|
||||
)}
|
||||
{/* {header.column.getCanFilter() ? (
|
||||
<div>
|
||||
<Filter column={header.column} table={table} />
|
||||
</div>
|
||||
) : null} */}
|
||||
</div>
|
||||
)}
|
||||
</th>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
))}
|
||||
</thead>
|
||||
<tbody>
|
||||
<>
|
||||
{table.getRowModel().rows.map((row) => {
|
||||
return (
|
||||
<tr className='group/tr outline-solid outline-transparent data-[focus-visible=true]:z-10 data-[focus-visible=true]:outline-2 data-[focus-visible=true]:outline-focus data-[focus-visible=true]:outline-offset-2' key={row.id}>
|
||||
{row.getVisibleCells().map((cell) => {
|
||||
return (
|
||||
<td
|
||||
className={`${cell.column.columnDef.meta?.align ? cell.column.columnDef.meta?.align : ''} py-2 px-3 relative align-middle whitespace-normal text-small font-normal [&>*]:z-1 [&>*]:relative outline-solid outline-transparent data-[focus-visible=true]:z-10 data-[focus-visible=true]:outline-2 data-[focus-visible=true]:outline-focus data-[focus-visible=true]:outline-offset-2 before:pointer-events-none before:content-[''] before:absolute before:z-0 before:inset-0 before:opacity-0 data-[selected=true]:before:opacity-100 group-data-[disabled=true]/tr:text-foreground-300 group-data-[disabled=true]/tr:cursor-not-allowed before:bg-default/60 data-[selected=true]:text-default-foreground first:before:rounded-s-lg last:before:rounded-e-lg text-start`}
|
||||
key={cell.id}
|
||||
>
|
||||
{flexRender(
|
||||
cell.column.columnDef.cell,
|
||||
cell.getContext()
|
||||
)}
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
{state.experiences.length > 0 && screenSize === ScreenSize.SM &&
|
||||
<div className='col-span-12'>
|
||||
<>
|
||||
{table.getRowModel().rows.map((row) => {
|
||||
return (
|
||||
<div className='card bg-base-100 border border-base-300 mb-5'>
|
||||
<div className={`card-body ${screenSize === ScreenSize.SM || screenSize === ScreenSize.MD ? 'p-4' : ''}`} key={row.id}>
|
||||
<div className={`grid grid-cols-12 gap-3`}>
|
||||
<>
|
||||
{row.getVisibleCells().map((cell) => {
|
||||
return (
|
||||
<>
|
||||
{cell.column.columnDef.header !== 'Actions' &&
|
||||
<>
|
||||
<div className='col-span-10 self-center'>
|
||||
<span>{flexRender(cell.column.columnDef.cell, cell.getContext())}</span>
|
||||
</div>
|
||||
<div className='col-span-2'>
|
||||
<Actions id={row.original.id} />
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
</>
|
||||
)
|
||||
})}
|
||||
</>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
{state.isFormOpen &&
|
||||
<ExperienceForm
|
||||
isDrawerOpen={state.isFormOpen}
|
||||
mode={state.formMode}
|
||||
onOpenClose={(mode) => onOpenCloseExperienceForm(mode)}
|
||||
experienceId={state.selectedExperienceId}
|
||||
/>
|
||||
}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default Experiences;
|
||||
@@ -0,0 +1,14 @@
|
||||
import { FormMode } from '../../enums/formMode';
|
||||
import { Alert } from '../../interfaces';
|
||||
import { Experience } from './Experience.interface';
|
||||
|
||||
export interface ExperiencesState {
|
||||
alert: Alert | undefined;
|
||||
experiences: Experience[];
|
||||
formMode: FormMode;
|
||||
isConfirmDialogLoading: boolean;
|
||||
isConfirmDialogOpen: boolean;
|
||||
isFormOpen: boolean;
|
||||
isLoading: boolean;
|
||||
selectedExperienceId: string | undefined;
|
||||
}
|
||||
93
client/src/components/experiences/reducer.ts
Normal file
93
client/src/components/experiences/reducer.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { FormMode } from '../../enums/formMode';
|
||||
import { ExperiencesState } from './ExperiencesState.interface'
|
||||
import { Experience } from './Experience.interface';
|
||||
import { Alert } from '../../interfaces';
|
||||
|
||||
type Action =
|
||||
| {
|
||||
type: 'SET_DELETE';
|
||||
payload: {
|
||||
isConfirmationDialogOpen: boolean;
|
||||
selectedExperienceId: string | undefined;
|
||||
};
|
||||
}
|
||||
| { type: 'SET_EXPERIENCES'; payload: Experience[] }
|
||||
| { type: 'SET_ALERT'; payload: Alert | undefined }
|
||||
| { type: 'SET_FORM_MODE'; payload: FormMode }
|
||||
| { type: 'SET_IS_CONFIRMATION_DIALOG_LOADING'; payload: boolean }
|
||||
| { type: 'SET_IS_LOADING'; payload: boolean }
|
||||
| {
|
||||
type: 'SET_OPEN_CLOSE_EXPERIENCE_FORM';
|
||||
payload: {
|
||||
formMode: FormMode;
|
||||
selectedExperienceId: string | undefined;
|
||||
isFormOpen: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
export const initialState: ExperiencesState = {
|
||||
alert: undefined,
|
||||
formMode: FormMode.CANCEL,
|
||||
isConfirmDialogLoading: false,
|
||||
isConfirmDialogOpen: false,
|
||||
isFormOpen: false,
|
||||
isLoading: false,
|
||||
experiences: [],
|
||||
selectedExperienceId: undefined
|
||||
};
|
||||
|
||||
export const reducer = (
|
||||
state: ExperiencesState,
|
||||
action: Action
|
||||
): ExperiencesState => {
|
||||
switch (action.type) {
|
||||
case 'SET_DELETE': {
|
||||
return {
|
||||
...state,
|
||||
isConfirmDialogOpen: action.payload.isConfirmationDialogOpen,
|
||||
selectedExperienceId: action.payload.selectedExperienceId
|
||||
};
|
||||
}
|
||||
case 'SET_EXPERIENCES': {
|
||||
return {
|
||||
...state,
|
||||
experiences: action.payload
|
||||
};
|
||||
}
|
||||
case 'SET_ALERT': {
|
||||
return {
|
||||
...state,
|
||||
alert: action.payload
|
||||
};
|
||||
}
|
||||
case 'SET_FORM_MODE': {
|
||||
return {
|
||||
...state,
|
||||
formMode: action.payload
|
||||
};
|
||||
}
|
||||
case 'SET_IS_CONFIRMATION_DIALOG_LOADING': {
|
||||
return {
|
||||
...state,
|
||||
isConfirmDialogLoading: action.payload
|
||||
};
|
||||
}
|
||||
case 'SET_IS_LOADING': {
|
||||
return {
|
||||
...state,
|
||||
isLoading: action.payload
|
||||
};
|
||||
}
|
||||
case 'SET_OPEN_CLOSE_EXPERIENCE_FORM': {
|
||||
return {
|
||||
...state,
|
||||
formMode: action.payload.formMode,
|
||||
isFormOpen: action.payload.isFormOpen,
|
||||
selectedExperienceId: action.payload.selectedExperienceId
|
||||
};
|
||||
}
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user