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:
@@ -36,13 +36,14 @@ export const getServiceById = async (serviceId) => {
|
||||
* @param {object} data - Service data
|
||||
*/
|
||||
export const createService = async (userId, data) => {
|
||||
const { name, price, description } = data;
|
||||
const { name, price, pricingTiers, description } = data;
|
||||
|
||||
const [newService] = await db
|
||||
.insert(services)
|
||||
.values({
|
||||
name,
|
||||
price,
|
||||
pricingTiers: pricingTiers || null,
|
||||
description: description || null,
|
||||
createdBy: userId,
|
||||
})
|
||||
@@ -59,13 +60,14 @@ export const createService = async (userId, data) => {
|
||||
export const updateService = async (serviceId, data) => {
|
||||
const service = await getServiceById(serviceId);
|
||||
|
||||
const { name, price, description } = data;
|
||||
const { name, price, pricingTiers, description } = data;
|
||||
|
||||
const [updated] = await db
|
||||
.update(services)
|
||||
.set({
|
||||
name: name !== undefined ? name : service.name,
|
||||
price: price !== undefined ? price : service.price,
|
||||
pricingTiers: pricingTiers !== undefined ? pricingTiers : service.pricingTiers,
|
||||
description: description !== undefined ? description : service.description,
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
|
||||
@@ -474,7 +474,18 @@ export const generateMonthlyTimesheet = async (userId, year, month) => {
|
||||
);
|
||||
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);
|
||||
let savedFilePath = null;
|
||||
|
||||
@@ -840,7 +851,19 @@ export const generateCompanyTimesheet = async (userId, year, month, companyId) =
|
||||
);
|
||||
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);
|
||||
let savedFilePath = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user