import { format } from 'date-fns';
import { SalariesProvider } from '../providers/salaries.provider.js';
export const updateSalaryRecord = async (_, { salaryRecord }, { injector }) => {
    try {
        const formattedMonth = salaryRecord.month && salaryRecord.month.length !== 7
            ? format(new Date(salaryRecord.month), 'yyyy-MM')
            : salaryRecord.month;
        const res = await injector.get(SalariesProvider).updateSalaryRecord({
            ...salaryRecord,
            month: formattedMonth,
        });
        if (res.length !== 1) {
            throw new Error(`Failed to update salary record of employee ID=${salaryRecord.employeeId} on month ${salaryRecord.month}`);
        }
        return {
            salaryRecord: res[0],
        };
    }
    catch (e) {
        return {
            __typename: 'CommonError',
            message: e?.message ??
                e?.errors.map(e => e.message).toString() ??
                'Unknown error',
        };
    }
};
//# sourceMappingURL=update-salary.resolver.js.map