Skip to content

Commit

Permalink
fix: update project name when performing soft delete
Browse files Browse the repository at this point in the history
  • Loading branch information
sachdevavaibhav committed Feb 28, 2025
1 parent 4771190 commit de6dde9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/dataController/__test__/projects.controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ describe('ProjectsController', () => {
projectId: 123,
status: 'Archived' as IArchiveProjects['status'],
userId: 456,
updatedName: 'Website_2025-02-28T12:01:12.807Z',
}
const mockResponse = {affectedRows: 1}

Expand All @@ -167,6 +168,7 @@ describe('ProjectsController', () => {
projectId: 123,
status: 'Archived' as IArchiveProjects['status'],
userId: 456,
updatedName: 'Website_2025-02-28T12:01:12.807Z',
}

const mockError = new Error('Database error')
Expand Down
1 change: 1 addition & 0 deletions app/dataController/projects.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IArchiveProjects {
projectId: number
status: 'Active' | 'Archived' | 'Deleted'
userId: number
updatedName?: string
}

const ProjectsController = {
Expand Down
10 changes: 9 additions & 1 deletion app/db/dao/projects.dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,19 @@ const ProjectsDao = {
projectId,
status,
userId,
updatedName,
}: IArchiveProjects) => {
try {
if (status === 'Archived' && !updatedName) {
throw new Error('Updated name is required for archiving the project')
}
const archiveProject = await dbClient
.update(projects)
.set({status, updatedBy: userId})
.set({
status,
updatedBy: userId,
...(updatedName && {projectName: updatedName}),
})
.where(eq(projects.projectId, projectId))
return archiveProject
} catch (error: any) {
Expand Down
1 change: 1 addition & 0 deletions app/routes/api/v1/__tests__/updateProjectStatus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('Update Project Status - Action Function', () => {
const requestData = {
projectId: 123,
status: 'Archived',
updatedName: 'Website_2025-02-28T12:01:12.807Z',
}
const request = new Request('http://localhost', {
method: 'POST',
Expand Down
4 changes: 3 additions & 1 deletion app/screens/Projects/ProjectListColumnConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,12 @@ export const PROJECT_LIST_COLUMN_CONFIG: ColumnDef<IProjectItem>[] = [

const handleConfirmDelete = async (event: React.MouseEvent) => {
const projectId = row.original.projectId
const timestampString = new Date().toISOString()
const updatedName = `${row.original.projectName}_${timestampString}`
const status = 'Archived'

updateProjectStatus.submit(
{projectId, status},
{projectId, status, updatedName},
{
method: 'put',
action: `/${API.EditProjectStatus}`,
Expand Down

0 comments on commit de6dde9

Please # to comment.