Skip to content

Commit

Permalink
feat(api): add createdOn field to WorkspaceMember model and update re…
Browse files Browse the repository at this point in the history
…lated services
  • Loading branch information
muntaxir4 committed Dec 11, 2024
1 parent c233a9c commit b02fbf7
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "WorkspaceMember" ADD COLUMN "createdOn" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
1 change: 1 addition & 0 deletions apps/api/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ model WorkspaceMember {
workspaceId String
invitationAccepted Boolean @default(false)
roles WorkspaceMemberRoleAssociation[]
createdOn DateTime @default(now())
@@unique([workspaceId, userId])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,11 +879,14 @@ export class WorkspaceMembershipService {
roleSet.add(role)
}

const invitedOn = new Date()

// Create the workspace membership
const createMembership = this.prisma.workspaceMember.create({
data: {
workspaceId: workspace.id,
userId,
createdOn: invitedOn,
roles: {
create: Array.from(roleSet).map((role) => ({
role: {
Expand All @@ -904,7 +907,7 @@ export class WorkspaceMembershipService {
workspace.name,
`${process.env.WORKSPACE_FRONTEND_URL}/workspace/${workspace.slug}/join`,
currentUser.name,
new Date().toISOString(),
invitedOn.toISOString(),
true
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ describe('Workspace Membership Controller Tests', () => {
id: expect.any(String),
userId: user2.id,
workspaceId: workspace1.id,
invitationAccepted: false
invitationAccepted: false,
createdOn: expect.any(Date)
})
})

Expand Down Expand Up @@ -909,7 +910,8 @@ describe('Workspace Membership Controller Tests', () => {
id: expect.any(String),
userId: user2.id,
workspaceId: workspace1.id,
invitationAccepted: true
invitationAccepted: true,
createdOn: expect.any(Date)
})
})

Expand Down
12 changes: 10 additions & 2 deletions apps/api/src/workspace/service/workspace.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ export class WorkspaceService {
}
}
}
}
},
createdOn: true
}
})

Expand Down Expand Up @@ -479,7 +480,14 @@ export class WorkspaceService {
search
})

return { items, metadata }
return {
items: items.map((item) => ({
...item,
invitedOn: item.createdOn,
createdOn: undefined
})),
metadata
}
}

/**
Expand Down
22 changes: 19 additions & 3 deletions apps/api/src/workspace/workspace.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ describe('Workspace Controller Tests', () => {
id: expect.any(String),
userId: user1.id,
workspaceId: workspace1.id,
invitationAccepted: true
invitationAccepted: true,
createdOn: expect.any(Date)
})
})
})
Expand Down Expand Up @@ -503,8 +504,24 @@ describe('Workspace Controller Tests', () => {
const body = response.json()

expect(body.items).toHaveLength(1)
expect(body.items[0].workspace.id).toBe(workspace1.id)
expect(body.items[0].workspace.slug).not.toBe(workspace2.slug)
expect(body.items[0]).toEqual({
invitedOn: expect.any(Date.toString()),
workspace: {
icon: workspace1.icon,
id: workspace1.id,
name: workspace1.name,
slug: workspace1.slug
},
roles: [
{
role: {
name: memberRole.name,
colorCode: memberRole.colorCode
}
}
]
})
expect(body.metadata.totalCount).toBe(1)
expect(body.metadata.links.self).toEqual(
`/workspace/invitations?page=0&limit=10&sort=name&order=asc&search=`
Expand Down Expand Up @@ -567,7 +584,6 @@ describe('Workspace Controller Tests', () => {
})

const body = response.json()
console.log(body)
expect(body.items).toHaveLength(0)
expect(body.metadata).toEqual({})
})
Expand Down

0 comments on commit b02fbf7

Please sign in to comment.