Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: update project name when performing soft delete #31

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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