Skip to content

Commit

Permalink
only meetings that exist in the database are returned by openTables (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogge authored Aug 15, 2024
1 parent 4f027b6 commit 6fba9ae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion backend/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"coverageThreshold": {
"global": {
"statements": 95,
"branches": 79,
"branches": 77,
"functions": 96,
"lines": 96
}
Expand Down
16 changes: 3 additions & 13 deletions backend/src/graphql/resolvers/TableResolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ describe('TableResolver', () => {
})
})

describe('no attendees', () => {
describe('meeting is not in database', () => {
beforeEach(() => {
getMeetingsMock.mockResolvedValue([
{
Expand Down Expand Up @@ -1163,17 +1163,7 @@ describe('TableResolver', () => {
kind: 'single',
singleResult: {
data: {
openTables: [
{
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
id: expect.any(Number),
meetingName: 'Dreammall Entwicklung',
meetingID: 'Dreammall-Entwicklung',
participantCount: 0,
startTime: '1718189',
attendees: [],
},
],
openTables: [],
},
errors: undefined,
},
Expand Down Expand Up @@ -1335,7 +1325,7 @@ describe('TableResolver', () => {
])
})

it('returns empty array', async () => {
it('returns table with all attendees', async () => {
await expect(
testServer.executeOperation(
{
Expand Down
13 changes: 8 additions & 5 deletions backend/src/graphql/resolvers/TableResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,20 +326,23 @@ export class TableResolver {

const openTablesFromOpenMeetings = async (meetings: MeetingInfo[]): Promise<OpenTable[]> => {
if (meetings.length) {
const dbMeetingsIdMap = await prisma.meeting.findMany({
const dbMeetings = await prisma.meeting.findMany({
where: {
meetingID: { in: meetings.map((m: MeetingInfo) => m.meetingID) },
},
select: {
id: true,
meetingID: true,
attendeePW: true,
},
})
return meetings.map((m: MeetingInfo) => {
const pw = dbMeetingsIdMap.find((pw) => pw.meetingID === m.meetingID)
return new OpenTable(m, pw?.id ? pw?.id : 0)

const openTables: OpenTable[] = []

dbMeetings.forEach((ids) => {
const meeting = meetings.find((m) => ids.meetingID === m.meetingID)
if (meeting) openTables.push(new OpenTable(meeting, ids.id ? ids.id : 0))
})
return openTables
}

return []
Expand Down

0 comments on commit 6fba9ae

Please sign in to comment.