fix: Services pricing tiers and timesheet naming

- Add pricingTiers field handling in createService/updateService
- Fix timesheet filename to use firstName-lastName-vykazprace-YYYY-MM.xlsx
- Fix company timesheet filename format similarly
- Removed timestamp from filename for cleaner naming

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
richardtekula
2026-01-22 11:30:17 +01:00
parent 5ade261cb2
commit 5dde025855
2 changed files with 29 additions and 4 deletions

View File

@@ -36,13 +36,14 @@ export const getServiceById = async (serviceId) => {
* @param {object} data - Service data * @param {object} data - Service data
*/ */
export const createService = async (userId, data) => { export const createService = async (userId, data) => {
const { name, price, description } = data; const { name, price, pricingTiers, description } = data;
const [newService] = await db const [newService] = await db
.insert(services) .insert(services)
.values({ .values({
name, name,
price, price,
pricingTiers: pricingTiers || null,
description: description || null, description: description || null,
createdBy: userId, createdBy: userId,
}) })
@@ -59,13 +60,14 @@ export const createService = async (userId, data) => {
export const updateService = async (serviceId, data) => { export const updateService = async (serviceId, data) => {
const service = await getServiceById(serviceId); const service = await getServiceById(serviceId);
const { name, price, description } = data; const { name, price, pricingTiers, description } = data;
const [updated] = await db const [updated] = await db
.update(services) .update(services)
.set({ .set({
name: name !== undefined ? name : service.name, name: name !== undefined ? name : service.name,
price: price !== undefined ? price : service.price, price: price !== undefined ? price : service.price,
pricingTiers: pricingTiers !== undefined ? pricingTiers : service.pricingTiers,
description: description !== undefined ? description : service.description, description: description !== undefined ? description : service.description,
updatedAt: new Date(), updatedAt: new Date(),
}) })

View File

@@ -474,7 +474,18 @@ export const generateMonthlyTimesheet = async (userId, year, month) => {
); );
await fs.mkdir(uploadsDir, { recursive: true }); await fs.mkdir(uploadsDir, { recursive: true });
const filename = `timesheet-${periodLabel}-${Date.now()}.xlsx`; // Generate user-friendly filename
let namePrefix;
if (user.firstName && user.lastName) {
namePrefix = `${user.firstName}-${user.lastName}`.toLowerCase().replace(/\s+/g, '-');
} else if (user.firstName) {
namePrefix = user.firstName.toLowerCase().replace(/\s+/g, '-');
} else if (user.username) {
namePrefix = user.username.toLowerCase().replace(/\s+/g, '-');
} else {
namePrefix = 'timesheet';
}
const filename = `${namePrefix}-vykazprace-${periodLabel}.xlsx`;
const filePath = path.join(uploadsDir, filename); const filePath = path.join(uploadsDir, filename);
let savedFilePath = null; let savedFilePath = null;
@@ -840,7 +851,19 @@ export const generateCompanyTimesheet = async (userId, year, month, companyId) =
); );
await fs.mkdir(uploadsDir, { recursive: true }); await fs.mkdir(uploadsDir, { recursive: true });
const filename = `company-timesheet-${company.name.replace(/[^a-zA-Z0-9]/g, '_')}-${periodLabel}-${Date.now()}.xlsx`; // Generate user-friendly filename
let namePrefix;
if (user.firstName && user.lastName) {
namePrefix = `${user.firstName}-${user.lastName}`.toLowerCase().replace(/\s+/g, '-');
} else if (user.firstName) {
namePrefix = user.firstName.toLowerCase().replace(/\s+/g, '-');
} else if (user.username) {
namePrefix = user.username.toLowerCase().replace(/\s+/g, '-');
} else {
namePrefix = 'timesheet';
}
const companySlug = company.name.replace(/[^a-zA-Z0-9]/g, '_').toLowerCase();
const filename = `${namePrefix}-vykazprace-${companySlug}-${periodLabel}.xlsx`;
const filePath = path.join(uploadsDir, filename); const filePath = path.join(uploadsDir, filename);
let savedFilePath = null; let savedFilePath = null;