communication type typing

This commit is contained in:
Julian Krauser 2024-09-18 09:43:02 +02:00
parent f673dec5fa
commit 72c47ba212
5 changed files with 34 additions and 8 deletions

View file

@ -1,12 +1,14 @@
import { CommunicationFieldType } from "../type/fieldTypes";
export interface CreateCommunicationTypeCommand { export interface CreateCommunicationTypeCommand {
type: string; type: string;
useColumns: Array<string>; useColumns: Array<CommunicationFieldType>;
} }
export interface UpdateCommunicationTypeCommand { export interface UpdateCommunicationTypeCommand {
id: number; id: number;
type: string; type: string;
useColumns: Array<string>; useColumns: Array<CommunicationFieldType>;
} }
export interface DeleteCommunicationTypeCommand { export interface DeleteCommunicationTypeCommand {

View file

@ -116,6 +116,12 @@ export async function getCommunicationsByMember(req: Request, res: Response): Pr
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
export async function createMember(req: Request, res: Response): Promise<any> { export async function createMember(req: Request, res: Response): Promise<any> {
const salutation = req.body.salutation;
const firstname = req.body.firstname;
const lastname = req.body.lastname;
const nameaffix = req.body.nameaffix;
const birthdate = req.body.birthdate;
res.status(200).send(0); res.status(200).send(0);
} }
@ -187,6 +193,11 @@ export async function addCommunicationToMember(req: Request, res: Response): Pro
*/ */
export async function updateMemberById(req: Request, res: Response): Promise<any> { export async function updateMemberById(req: Request, res: Response): Promise<any> {
const memberId = parseInt(req.params.id); const memberId = parseInt(req.params.id);
const salutation = req.body.salutation;
const firstname = req.body.firstname;
const lastname = req.body.lastname;
const nameaffix = req.body.nameaffix;
const birthdate = req.body.birthdate;
res.sendStatus(204); res.sendStatus(204);
} }

View file

@ -1,5 +1,6 @@
import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm"; import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm";
import { communication } from "./communication"; import { communication } from "./communication";
import { CommunicationFieldType, communicationFieldTypes } from "../type/fieldTypes";
@Entity() @Entity()
export class communicationType { export class communicationType {
@ -14,15 +15,15 @@ export class communicationType {
length: 255, length: 255,
default: "", default: "",
transformer: { transformer: {
from(value: string): Array<string> { from(value: string): Array<CommunicationFieldType> {
return (value ?? "").split(","); return communicationFieldTypes.filter((e) => value?.includes(e));
}, },
to(value: Array<string>): string { to(value: Array<CommunicationFieldType>): string {
return (value ?? []).join(","); return value.filter((e) => communicationFieldTypes.includes(e)).join(",");
}, },
}, },
}) })
useColumns: Array<string>; useColumns: Array<CommunicationFieldType>;
@OneToMany(() => communication, (communication) => communication.type) @OneToMany(() => communication, (communication) => communication.type)
communications: communication[]; communications: communication[];

10
src/type/fieldTypes.ts Normal file
View file

@ -0,0 +1,10 @@
export type CommunicationFieldType = "mobile" | "email" | "city" | "street" | "streetNumber" | "streetNumberAddition";
export const communicationFieldTypes: Array<CommunicationFieldType> = [
"mobile",
"email",
"city",
"street",
"streetNumber",
"streetNumberAddition",
];

View file

@ -1,5 +1,7 @@
import { CommunicationFieldType } from "../../type/fieldTypes";
export interface CommunicationTypeViewModel { export interface CommunicationTypeViewModel {
id: number; id: number;
type: string; type: string;
fields: Array<string>; fields: Array<CommunicationFieldType>;
} }