Commit f3be6095 authored by mechtelm's avatar mechtelm
Browse files

Add endpoint to get staff list

parent f0b0888d
......@@ -52,6 +52,32 @@
}
}
},
"dto": {
"projectType": "library",
"root": "libs/dto",
"sourceRoot": "libs/dto/src",
"prefix": "studio-lite",
"architect": {
"test": {
"builder": "@nrwl/jest:jest",
"outputs": ["coverage/libs/iqb-components"],
"options": {
"jestConfig": "libs/dto/jest.config.js",
"passWithNoTests": true
}
},
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": [
"libs/dto/src/**/*.ts",
"libs/dto/src/**/*.html"
]
}
}
},
"tags": []
},
"frontend": {
"projectType": "application",
"root": "apps/frontend",
......@@ -200,32 +226,6 @@
}
},
"tags": []
},
"dto": {
"projectType": "library",
"root": "libs/dto",
"sourceRoot": "libs/dto/src",
"prefix": "studio-lite",
"architect": {
"test": {
"builder": "@nrwl/jest:jest",
"outputs": ["coverage/libs/iqb-components"],
"options": {
"jestConfig": "libs/dto/jest.config.js",
"passWithNoTests": true
}
},
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": [
"libs/dto/src/**/*.ts",
"libs/dto/src/**/*.html"
]
}
}
},
"tags": []
}
}
}
......@@ -5,11 +5,13 @@ import { AppService } from './app.service';
import {AppAdminModule} from "./app-admin/app-admin.module";
import {DatabaseModule} from "./database/database.module";
import {AuthModule} from "./auth/auth.module";
import {StaffModule} from "./staff/staff.module";
@Module({
imports: [
AppAdminModule,
AuthModule,
StaffModule,
DatabaseModule
],
controllers: [AppController],
......
......@@ -4,11 +4,14 @@ import User from './entities/user.entity';
import {UsersService} from "./services/users.service";
import Config from "./entities/config.entity";
import {ConfigService} from "./services/config.service";
import Staff from "./entities/staff-member.entity";
import {StaffService} from "./services/staff.service";
@Module({
imports: [
User,
Config,
Staff,
TypeOrmModule.forRootAsync({
useFactory: () => ({
"type": "postgres",
......@@ -17,21 +20,24 @@ import {ConfigService} from "./services/config.service";
"username": process.env.POSTGRES_USER,
"password": process.env.POSTGRES_PASSWORD,
"database": process.env.POSTGRES_DB,
"entities": [User, Config],
"entities": [User, Config, Staff],
"synchronize": false
})
}
),
TypeOrmModule.forFeature([User, Config])
TypeOrmModule.forFeature([User, Config, Staff])
],
providers: [
UsersService,
StaffService,
ConfigService
],
exports: [
User,
Config,
Staff,
UsersService,
StaffService,
ConfigService
]
})
......
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import {StaffMemberMetadataDto} from "../../../../../../libs/dto/src";
@Entity()
class Staff {
@PrimaryGeneratedColumn()
public id: number;
@Column()
public name: string;
@Column({
name: 'first_name'
})
public firstName: string;
@Column()
public address: string | null;
@Column({
name: 'cn'
})
public canonicalName: string | null;
@Column()
public salutation: string | null;
@Column({
name: 'contract_type'
})
public contractType: string | null;
@Column({
type: 'date',
name: 'contract_start'
})
contractStart: string | null;
@Column({
type: 'date',
name: 'contract_end'
})
contractEnd: string | null;
@Column({
type: 'jsonb',
array: false,
default: () => "'{}'",
nullable: false,
})
public metadata: StaffMemberMetadataDto;
@Column({
name: 'payroll_number'
})
public payrollNumber: string | null;
}
export default Staff;
import { Test, TestingModule } from '@nestjs/testing';
import { StaffService } from './staff.service';
describe('StaffService', () => {
let service: StaffService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [StaffService],
}).compile();
service = module.get<StaffService>(StaffService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
import { Injectable } from '@nestjs/common';
import {InjectRepository} from "@nestjs/typeorm";
import {Repository} from "typeorm";
import Staff from "../entities/staff-member.entity";
import {StaffMemberInListDto, UserInListDto} from "../../../../../../libs/dto/src";
@Injectable()
export class StaffService {
constructor(
@InjectRepository(Staff)
private staffRepository: Repository<Staff>,
) {}
async findAll(): Promise<StaffMemberInListDto[]> {
const staffMembers: Staff[] = await this.staffRepository.find({order: {name: 'ASC'}});
const returnStaff: StaffMemberInListDto[] = [];
staffMembers.forEach(staffMember => {
returnStaff.push(<StaffMemberInListDto>{
id: staffMember.id,
name: staffMember.name,
firstName: staffMember.firstName,
canonicalName: staffMember.canonicalName,
contractStart: staffMember.contractStart,
contractEnd: staffMember.contractEnd,
contractType: staffMember.contractType
})
});
return returnStaff;
}
}
import { Test, TestingModule } from '@nestjs/testing';
import { StaffController } from './staff.controller';
describe('StaffController', () => {
let controller: StaffController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [StaffController],
}).compile();
controller = module.get<StaffController>(StaffController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
import {Controller, Get, UseGuards} from '@nestjs/common';
import {JwtAuthGuard} from "../auth/jwt-auth.guard";
import {IsAdminGuard} from "../app-admin/is-admin.guard";
import {ApiBearerAuth, ApiCreatedResponse, ApiTags} from "@nestjs/swagger";
import {StaffMemberInListDto, UserInListDto} from "../../../../../libs/dto/src";
import {StaffService} from "../database/services/staff.service";
@Controller('staff')
export class StaffController {
constructor(
private staffService: StaffService
) {}
@Get()
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiCreatedResponse({
type: [StaffMemberInListDto],
})
@ApiTags('staff')
async findAll(): Promise<StaffMemberInListDto[]> {
return this.staffService.findAll();
}
}
import { Module } from '@nestjs/common';
import {DatabaseModule} from "../database/database.module";
import {AuthModule} from "../auth/auth.module";
import {StaffController} from "./staff.controller";
@Module({
imports: [
DatabaseModule,
AuthModule
],
controllers: [
StaffController
]
})
export class StaffModule {}
export {StaffMemberInListDto} from "./lib/staff/staff-member-in-list-dto";
export {StaffMemberMetadataDto} from "./lib/staff/staff-member-metadata-dto";
export {AuthDataDto} from "./lib/auth-data-dto";
export {ChangePasswordDto} from "./lib/change-password-dto";
export {ConfigFullDto} from "./lib/config/config-full-dto";
......
import { ApiProperty } from '@nestjs/swagger';
export class StaffMemberInListDto {
@ApiProperty()
id!: number;
@ApiProperty()
name!: string;
@ApiProperty()
firstName?: string;
@ApiProperty()
canonicalName?: string;
@ApiProperty()
contractStart?: string;
@ApiProperty()
contractEnd?: string;
@ApiProperty()
contractType?: string;
}
import { ApiProperty } from '@nestjs/swagger';
export class StaffMemberMetadataDto {
@ApiProperty()
dummy1 = '';
@ApiProperty()
dummy2 = '';
@ApiProperty()
dummy3?: string[];
}
......@@ -25,14 +25,14 @@ all_lines.forEach(line => {
}
if (end_date) {
const valuesString = "'" + data[2] + "', '" + data[3] + "', '" + data[0] + "', " + start_date + ", " + end_date + ", '" + data[1] + "'";
const sql = 'INSERT INTO public.staff (name, surname, contract_type, contract_start, contract_end, cms_id) VALUES (' + valuesString + ');';
const sql = 'INSERT INTO public.staff (name, first_name, contract_type, contract_start, contract_end, payroll_number) VALUES (' + valuesString + ');';
pool.query(sql, function(err, result){
console.log(err, result);
});
} else {
console.log('###');
const valuesString = "'" + data[2] + "', '" + data[3] + "', '" + data[0] + "', " + start_date + ", '" + data[1] + "'";
const sql = 'INSERT INTO public.staff (name, surname, contract_type, contract_start, cms_id) VALUES (' + valuesString + ');';
const sql = 'INSERT INTO public.staff (name, first_name, contract_type, contract_start, payroll_number) VALUES (' + valuesString + ');';
pool.query(sql, function(err, result){
console.log(err, result);
});
......
IQB-Vertrag###9648000363###Yung###Phong###01.11.2015###30.04.2024
IQB-Vertrag###9648000564###Schneider###Wolfgang###01.01.2014###unbefristet
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment