gongxiangp2/lib/personnel-salary-contract.ts

21 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { z } from 'zod'
// Monetary values stay decimal strings from the form through the API and audit snapshots.
export const salaryAmountSchema = z.string().regex(/^(?:0|[1-9]\d{0,9})(?:\.\d{1,2})?$/, '请输入不小于 0、最多两位小数的金额(上限 9999999999.99)')
const requiredText = z.string().trim().min(1, '此项必填').max(100, '最多 100 字')
const optionalText = z.string().trim().max(100, '最多 100 字')
export const jobGradeSchema = z.string().trim().toUpperCase().regex(/^(?:[A-Z]\d{1,2})?$/, '请输入职级,例如P3、P4').default('')
export const salaryFieldsSchema = z.object({
name: requiredText, flowerName: optionalText, department: requiredText, brand: optionalText.optional(),
jobGrade: jobGradeSchema,
baseSalary: salaryAmountSchema, gradeSalary: salaryAmountSchema, performanceSalary: salaryAmountSchema,
}).strict()
const positionId = z.string().uuid('请选择岗位').nullable().optional()
export const createSalarySchema = salaryFieldsSchema.extend({ employeeProfileId: z.string().uuid('请选择花名册人员'), positionId }).strict()
export const updateSalarySchema = salaryFieldsSchema.extend({ revision: z.number().int().positive(), positionId }).strict()
export const deleteSalarySchema = z.object({ revision: z.number().int().positive() }).strict()
export type SalaryFields = Omit<z.infer<typeof salaryFieldsSchema>, 'jobGrade'> & { jobGrade?: string }
export type SalaryRecord = SalaryFields & { id: string; employeeProfileId: string; positionId?: string | null; organizationDepartment?: string | null; revision: number; updatedAt: string; deletedAt: string | null }
export type SalaryCandidate = { employeeProfileId: string; name: string; flowerName: string; department: string; organizationDepartment?: string | null; jobNumber: string | null }
export type SalaryPayload = { canEdit: boolean; records: SalaryRecord[] }