fix: Timesheet naming and todo auto-assign fixes
- Fix timesheet filename to use firstName-lastName format with username fallback - Remove auto-assign creator to todos (user must manually select assignees) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -76,12 +76,19 @@ const safeUnlink = async (filePath) => {
|
||||
}
|
||||
};
|
||||
|
||||
const generateTimesheetFileName = (firstName, lastName, year, month, fileExt) => {
|
||||
const cleanFirstName = (firstName || 'user').toLowerCase().replace(/\s+/g, '-');
|
||||
const cleanLastName = (lastName || '').toLowerCase().replace(/\s+/g, '-');
|
||||
const generateTimesheetFileName = (firstName, lastName, username, year, month, fileExt) => {
|
||||
let namePrefix;
|
||||
if (firstName && lastName) {
|
||||
namePrefix = `${firstName}-${lastName}`.toLowerCase().replace(/\s+/g, '-');
|
||||
} else if (firstName) {
|
||||
namePrefix = firstName.toLowerCase().replace(/\s+/g, '-');
|
||||
} else if (username) {
|
||||
namePrefix = username.toLowerCase().replace(/\s+/g, '-');
|
||||
} else {
|
||||
namePrefix = 'timesheet';
|
||||
}
|
||||
const monthStr = String(month).padStart(2, '0');
|
||||
const namePrefix = cleanLastName ? `${cleanFirstName}-${cleanLastName}` : cleanFirstName;
|
||||
return `${namePrefix}-timesheet-${year}-${monthStr}${fileExt}`;
|
||||
return `${namePrefix}-vykazprace-${year}-${monthStr}${fileExt}`;
|
||||
};
|
||||
|
||||
export const uploadTimesheet = async ({ userId, year, month, file }) => {
|
||||
@@ -91,7 +98,7 @@ export const uploadTimesheet = async ({ userId, year, month, file }) => {
|
||||
|
||||
// Fetch user info for filename generation
|
||||
const [user] = await db
|
||||
.select({ firstName: users.firstName, lastName: users.lastName })
|
||||
.select({ firstName: users.firstName, lastName: users.lastName, username: users.username })
|
||||
.from(users)
|
||||
.where(eq(users.id, userId))
|
||||
.limit(1);
|
||||
@@ -106,6 +113,7 @@ export const uploadTimesheet = async ({ userId, year, month, file }) => {
|
||||
const displayFileName = generateTimesheetFileName(
|
||||
user?.firstName,
|
||||
user?.lastName,
|
||||
user?.username,
|
||||
parsedYear,
|
||||
parsedMonth,
|
||||
fileExt
|
||||
|
||||
@@ -209,16 +209,6 @@ export const createTodo = async (userId, data) => {
|
||||
await db.insert(todoUsers).values(todoUserInserts);
|
||||
}
|
||||
|
||||
// Auto-assign the creator to the todo so they can access it (if not already assigned)
|
||||
const creatorAlreadyAssigned = assignedUserIds && assignedUserIds.includes(userId);
|
||||
if (!creatorAlreadyAssigned) {
|
||||
await db.insert(todoUsers).values({
|
||||
todoId: newTodo.id,
|
||||
userId: userId,
|
||||
assignedBy: userId,
|
||||
});
|
||||
}
|
||||
|
||||
// Send push notifications to assigned users (excluding creator)
|
||||
if (assignedUserIds && Array.isArray(assignedUserIds) && assignedUserIds.length > 0) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user