Удалены неиспользуемые импорты и функции из компонентов, улучшены стили и функциональность. Обновлены компоненты для работы с изображениями, добавлены новые интерфейсы и типы данных для сотрудников. Реализована логика загрузки расписания сотрудников через GraphQL, улучшен интерфейс взаимодействия с пользователем.
This commit is contained in:
@ -20,6 +20,63 @@ interface Context {
|
||||
}
|
||||
}
|
||||
|
||||
interface CreateEmployeeInput {
|
||||
firstName: string
|
||||
lastName: string
|
||||
middleName?: string
|
||||
birthDate?: string
|
||||
avatar?: string
|
||||
passportPhoto?: string
|
||||
passportSeries?: string
|
||||
passportNumber?: string
|
||||
passportIssued?: string
|
||||
passportDate?: string
|
||||
address?: string
|
||||
position: string
|
||||
department?: string
|
||||
hireDate: string
|
||||
salary?: number
|
||||
phone: string
|
||||
email?: string
|
||||
telegram?: string
|
||||
whatsapp?: string
|
||||
emergencyContact?: string
|
||||
emergencyPhone?: string
|
||||
}
|
||||
|
||||
interface UpdateEmployeeInput {
|
||||
firstName?: string
|
||||
lastName?: string
|
||||
middleName?: string
|
||||
birthDate?: string
|
||||
avatar?: string
|
||||
passportPhoto?: string
|
||||
passportSeries?: string
|
||||
passportNumber?: string
|
||||
passportIssued?: string
|
||||
passportDate?: string
|
||||
address?: string
|
||||
position?: string
|
||||
department?: string
|
||||
hireDate?: string
|
||||
salary?: number
|
||||
status?: 'ACTIVE' | 'VACATION' | 'SICK' | 'FIRED'
|
||||
phone?: string
|
||||
email?: string
|
||||
telegram?: string
|
||||
whatsapp?: string
|
||||
emergencyContact?: string
|
||||
emergencyPhone?: string
|
||||
}
|
||||
|
||||
interface UpdateScheduleInput {
|
||||
employeeId: string
|
||||
date: string
|
||||
status: 'WORK' | 'WEEKEND' | 'VACATION' | 'SICK' | 'ABSENT'
|
||||
hoursWorked?: number
|
||||
notes?: string
|
||||
}
|
||||
|
||||
interface AuthTokenPayload {
|
||||
userId: string
|
||||
phone: string
|
||||
@ -742,6 +799,59 @@ export const resolvers = {
|
||||
})
|
||||
|
||||
return employee
|
||||
},
|
||||
|
||||
// Получить табель сотрудника за месяц
|
||||
employeeSchedule: async (_: unknown, args: { employeeId: string; year: number; month: number }, context: Context) => {
|
||||
if (!context.user) {
|
||||
throw new GraphQLError('Требуется авторизация', {
|
||||
extensions: { code: 'UNAUTHENTICATED' }
|
||||
})
|
||||
}
|
||||
|
||||
const currentUser = await prisma.user.findUnique({
|
||||
where: { id: context.user.id },
|
||||
include: { organization: true }
|
||||
})
|
||||
|
||||
if (!currentUser?.organization) {
|
||||
throw new GraphQLError('У пользователя нет организации')
|
||||
}
|
||||
|
||||
if (currentUser.organization.type !== 'FULFILLMENT') {
|
||||
throw new GraphQLError('Доступно только для фулфилмент центров')
|
||||
}
|
||||
|
||||
// Проверяем что сотрудник принадлежит организации
|
||||
const employee = await prisma.employee.findFirst({
|
||||
where: {
|
||||
id: args.employeeId,
|
||||
organizationId: currentUser.organization.id
|
||||
}
|
||||
})
|
||||
|
||||
if (!employee) {
|
||||
throw new GraphQLError('Сотрудник не найден')
|
||||
}
|
||||
|
||||
// Получаем записи табеля за указанный месяц
|
||||
const startDate = new Date(args.year, args.month, 1)
|
||||
const endDate = new Date(args.year, args.month + 1, 0)
|
||||
|
||||
const scheduleRecords = await prisma.employeeSchedule.findMany({
|
||||
where: {
|
||||
employeeId: args.employeeId,
|
||||
date: {
|
||||
gte: startDate,
|
||||
lte: endDate
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
date: 'asc'
|
||||
}
|
||||
})
|
||||
|
||||
return scheduleRecords
|
||||
}
|
||||
},
|
||||
|
||||
@ -3110,7 +3220,7 @@ export const resolvers = {
|
||||
},
|
||||
|
||||
// Создать сотрудника
|
||||
createEmployee: async (_: unknown, args: { input: any }, context: Context) => {
|
||||
createEmployee: async (_: unknown, args: { input: CreateEmployeeInput }, context: Context) => {
|
||||
if (!context.user) {
|
||||
throw new GraphQLError('Требуется авторизация', {
|
||||
extensions: { code: 'UNAUTHENTICATED' }
|
||||
@ -3159,7 +3269,7 @@ export const resolvers = {
|
||||
},
|
||||
|
||||
// Обновить сотрудника
|
||||
updateEmployee: async (_: unknown, args: { id: string; input: any }, context: Context) => {
|
||||
updateEmployee: async (_: unknown, args: { id: string; input: UpdateEmployeeInput }, context: Context) => {
|
||||
if (!context.user) {
|
||||
throw new GraphQLError('Требуется авторизация', {
|
||||
extensions: { code: 'UNAUTHENTICATED' }
|
||||
@ -3247,7 +3357,7 @@ export const resolvers = {
|
||||
},
|
||||
|
||||
// Обновить табель сотрудника
|
||||
updateEmployeeSchedule: async (_: unknown, args: { input: any }, context: Context) => {
|
||||
updateEmployeeSchedule: async (_: unknown, args: { input: UpdateScheduleInput }, context: Context) => {
|
||||
if (!context.user) {
|
||||
throw new GraphQLError('Требуется авторизация', {
|
||||
extensions: { code: 'UNAUTHENTICATED' }
|
||||
@ -3441,6 +3551,11 @@ export const resolvers = {
|
||||
return parent.updatedAt.toISOString()
|
||||
}
|
||||
return parent.updatedAt
|
||||
},
|
||||
employee: async (parent: { employeeId: string }) => {
|
||||
return await prisma.employee.findUnique({
|
||||
where: { id: parent.employeeId }
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user