Files
turnosxpress/server/src/Models/Employees/Employees.Interface.ts
T

175 lines
4.4 KiB
TypeScript

import { TextObjectFilterResult } from "../../Models/TextObjectFilter.model";
import { IEmployeeDocument } from "./Employees.Adapter.Mongoose";
export type FindEmployeesParams = {
_id?: string;
name?: string;
companyId?: string;
userId?: string;
};
export type PaginateEmployeesParams = FindEmployeesParams & {
page: number;
limit: number;
};
export type PaginateEmployeesResults = {
data: IEmployee[];
page: number;
pages: number;
};
export enum EmployeeRoles {
ADMIN = "admin",
OWNER = "owner",
EMPLOYEE = "employee",
}
export type CreateEmployeeParams = {
companyId: string;
userId: string;
roles?: EmployeeRoles[];
calendarColor?: string;
limit?: number;
hostOk?: boolean;
sessionUser: string;
};
export type UpdateEmployeeParams = {
id: string;
calendarColor?: string;
limit?: number;
sessionUser: string;
};
export type UpdateEmployeeRolesParams = {
employeeId: string;
companyId: string;
roles: EmployeeRoles[];
calendarColor?: string;
limit?: number;
sessionUser: string;
};
export type FindEmployeesByIdParams = {
id?: string;
};
export type ValidateEmployeeParams = {
employeeId: string;
sessionUser: string;
};
export type DeleteEmployeesByCompany = {
companyId: string;
};
export type DeleteEmployeeParams = {
employeeId: string;
};
export type RemoveCollaboratorParams = {
employeeId: string;
companyId: string;
replacementEmployeeId?: string;
sessionUser: string;
};
export interface IEmployee {
id?: string;
companyId: string;
userId: string;
roles?: EmployeeRoles[];
calendarColor?: string;
limit?: number;
guestOk?: boolean;
hostOk?: boolean;
removed?: boolean;
removedAt?: Date;
removedBy?: string;
profileSnapshot?: {
firstName?: string;
lastName?: string;
email?: string;
avatar?: string;
};
}
export interface CompanyEmployeesView {
id: string;
companyId: string;
userId: string;
firstName: string;
lastName: string;
fullName: string;
avatar: string;
email: string;
roles: EmployeeRoles[];
guestOk: boolean;
hostOk: boolean;
fullOk: boolean;
calendarColor: string;
removed?: boolean;
removedAt?: Date;
profileSnapshot?: {
firstName?: string;
lastName?: string;
email?: string;
avatar?: string;
};
}
export interface PublicCompanyEmployeeView {
employeeId: string;
userId: string;
firstName: string;
lastName: string;
avatarUrl: string;
}
export interface FindPublicEmployeeParams {
employeeId: string;
}
export interface PublicEmployeeView {
employeeId: string;
firstName: string;
lastName: string;
avatarUrl: string;
}
export interface IncompleteCollaboratorView {
employeeId: string;
companyId: string;
companyName: string;
name: string;
missingServices: boolean;
missingSchedules: boolean;
}
export interface IEmployeesAdapter {
create(data: CreateEmployeeParams): Promise<IEmployee>;
delete(id: string): Promise<void>;
find(filters: FindEmployeesParams): Promise<IEmployee[]>;
findOne(filters: FindEmployeesParams): Promise<IEmployeeDocument | null>;
paginate(filters: PaginateEmployeesParams): Promise<PaginateEmployeesResults>;
}
export interface IEmployeesManager {
employees: IEmployeesAdapter;
checkRoleById(companyId: string, employeeId: string, role: EmployeeRoles): Promise<boolean>;
createEmployee(data: CreateEmployeeParams): Promise<IEmployee>;
updateEmployeeRoles(data: UpdateEmployeeRolesParams): Promise<void>;
update(data: UpdateEmployeeParams): Promise<void>;
findByCompanyId(data: FindEmployeesParams): Promise<CompanyEmployeesView[]>;
findPublicByCompanyId(data: FindEmployeesParams): Promise<PublicCompanyEmployeeView[]>;
findPublicByEmployeeId(data: FindPublicEmployeeParams): Promise<PublicEmployeeView>;
findById(data: FindEmployeesByIdParams): Promise<CompanyEmployeesView>;
textObjectFilter(data: FindEmployeesParams): Promise<TextObjectFilterResult[]>;
deleteEmployeesByCompany(data: DeleteEmployeesByCompany): Promise<void>;
deleteEmployee(data: DeleteEmployeeParams): Promise<void>;
rejectGuest(data: ValidateEmployeeParams): Promise<void>;
getIncompleteSetup(sessionUser: string): Promise<IncompleteCollaboratorView[]>;
removeCollaboratorFromCompany(data: RemoveCollaboratorParams): Promise<void>;
}