Skip to content

Commit 55a7228

Browse files
committed
migration out of date fix, more unit tests
1 parent a7b25f2 commit 55a7228

6 files changed

Lines changed: 614 additions & 77 deletions

File tree

src/backend/src/prisma/migrations/20260201001906_calendar/migration.sql

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,21 @@ CREATE TABLE "public"."Event_Type" (
111111
"dateDeleted" TIMESTAMP(3),
112112
"userCreatedId" TEXT NOT NULL,
113113
"userDeletedId" TEXT,
114-
"optionalMembers" BOOLEAN NOT NULL DEFAULT FALSE,
115-
"requiredMembers" BOOLEAN NOT NULL DEFAULT FALSE,
116-
"teams" BOOLEAN NOT NULL DEFAULT FALSE,
117-
"teamType" BOOLEAN NOT NULL DEFAULT FALSE,
118-
"location" BOOLEAN NOT NULL DEFAULT FALSE,
119-
"zoomLink" BOOLEAN NOT NULL DEFAULT FALSE,
120-
"shop" BOOLEAN NOT NULL DEFAULT FALSE,
121-
"machinery" BOOLEAN NOT NULL DEFAULT FALSE,
122-
"workPackage" BOOLEAN NOT NULL DEFAULT FALSE,
123-
"questionDocument" BOOLEAN NOT NULL DEFAULT FALSE,
124-
"documents" BOOLEAN NOT NULL DEFAULT FALSE,
125-
"description" BOOLEAN NOT NULL DEFAULT FALSE,
126-
"onlyHeadsOrAboveForEventCreation" BOOLEAN NOT NULL DEFAULT FALSE,
127-
"requiresConfirmation" BOOLEAN NOT NULL DEFAULT FALSE,
128-
"sendSlackNotifications" BOOLEAN NOT NULL DEFAULT FALSE,
114+
"optionalMembers" BOOLEAN NOT NULL,
115+
"requiredMembers" BOOLEAN NOT NULL,
116+
"teams" BOOLEAN NOT NULL,
117+
"teamType" BOOLEAN NOT NULL,
118+
"location" BOOLEAN NOT NULL,
119+
"zoomLink" BOOLEAN NOT NULL,
120+
"shop" BOOLEAN NOT NULL,
121+
"machinery" BOOLEAN NOT NULL,
122+
"workPackage" BOOLEAN NOT NULL,
123+
"questionDocument" BOOLEAN NOT NULL,
124+
"documents" BOOLEAN NOT NULL,
125+
"description" BOOLEAN NOT NULL,
126+
"onlyHeadsOrAboveForEventCreation" BOOLEAN NOT NULL,
127+
"requiresConfirmation" BOOLEAN NOT NULL,
128+
"sendSlackNotifications" BOOLEAN NOT NULL,
129129
"organizationId" TEXT NOT NULL,
130130

131131
CONSTRAINT "Event_Type_pkey" PRIMARY KEY ("eventTypeId")
@@ -345,7 +345,7 @@ ALTER TABLE "public"."Event_Type" ADD CONSTRAINT "Event_Type_userDeletedId_fkey"
345345
ALTER TABLE "public"."Event_Type" ADD CONSTRAINT "Event_Type_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "public"."Organization"("organizationId") ON DELETE RESTRICT ON UPDATE CASCADE;
346346

347347
-- AddForeignKey
348-
ALTER TABLE "public"."Schedule_Slot" ADD CONSTRAINT "Schedule_Slot_EventId_fkey" FOREIGN KEY ("eventId") REFERENCES "Event"("eventId") ON DELETE RESTRICT ON UPDATE CASCADE;
348+
ALTER TABLE "public"."Schedule_Slot" ADD CONSTRAINT "Schedule_Slot_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "Event"("eventId") ON DELETE RESTRICT ON UPDATE CASCADE;
349349

350350
-- AddForeignKey
351351
ALTER TABLE "public"."_affiliatedTeam" ADD CONSTRAINT "_affiliatedTeam_A_fkey" FOREIGN KEY ("A") REFERENCES "public"."Event"("eventId") ON DELETE CASCADE ON UPDATE CASCADE;

src/backend/src/prisma/schema.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ model Manufacturer {
975975

976976
model Shop {
977977
shopId String @id @default(uuid())
978-
name String @unique
978+
name String
979979
dateCreated DateTime @default(now())
980980
dateDeleted DateTime?
981981
userCreatedId String

src/backend/src/services/calendar.services.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,6 @@ export default class CalendarService {
759759
const updatedRequiredMembers = getPrismaQueryUserIds(await getUsers(requiredMemberIds));
760760
const updatedOptionalMembers = getPrismaQueryUserIds(await getUsers(optionalMemberIds));
761761

762-
let newStatus = status;
763-
764762
// Update the event with new data (excluding schedule slots)
765763
const updatedEvent = await prisma.event.update({
766764
where: { eventId },
@@ -777,7 +775,7 @@ export default class CalendarService {
777775
set: teamIds.map((teamId) => ({ teamId }))
778776
},
779777
...(teamTypeId !== undefined && { teamTypeId }),
780-
status: newStatus,
778+
status,
781779
shops: {
782780
set: shopIds.map((shopId) => ({ shopId }))
783781
},
@@ -2471,7 +2469,7 @@ export default class CalendarService {
24712469
}
24722470
}
24732471

2474-
// filters for members/teams
2472+
// filters for members/teams - event must match at least one of these if provided
24752473
const memberOrTeamFilter: any[] = [];
24762474

24772475
if (memberIds?.length) {
@@ -2515,6 +2513,19 @@ export default class CalendarService {
25152513
}
25162514
: undefined;
25172515

2516+
// Build the AND conditions - member/team filters AND time filters
2517+
const andConditions: any[] = [];
2518+
2519+
// If member/team filters are provided, require at least one to match
2520+
if (memberOrTeamFilter.length > 0) {
2521+
andConditions.push({ OR: memberOrTeamFilter });
2522+
}
2523+
2524+
// If time filters are provided, require at least one to match
2525+
if (startPeriod || endPeriod) {
2526+
andConditions.push({ OR: scheduleSlotsOrDateScheduled });
2527+
}
2528+
25182529
// get event using filter args
25192530
const events = await prisma.event.findMany({
25202531
where: {
@@ -2523,7 +2534,7 @@ export default class CalendarService {
25232534
eventTypeId: eventTypeIds?.length ? { in: eventTypeIds } : undefined,
25242535
approvalRequiredFromUserId: approvalIds?.length ? { in: approvalIds } : undefined,
25252536
approved: statuses?.length ? { in: statuses } : undefined,
2526-
OR: memberOrTeamFilter.concat(scheduleSlotsOrDateScheduled),
2537+
AND: andConditions.length > 0 ? andConditions : undefined,
25272538
...fromCalendar
25282539
},
25292540
...getEventQueryArgs(organization.organizationId),

src/backend/tests/test-utils.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import prisma from '../src/prisma/prisma.js';
1818
import { dbSeedAllUsers } from '../src/prisma/seed-data/users.seed.js';
1919
import TeamsService from '../src/services/teams.services.js';
2020
import ReimbursementRequestService from '../src/services/reimbursement-requests.services.js';
21-
import { DayOfWeek, Permission, RoleEnum, TaskPriority, TaskStatus } from 'shared';
21+
import { Permission, RoleEnum, TaskPriority, TaskStatus } from 'shared';
2222
import {
2323
batmanAppAdmin,
2424
batmanScheduleSettings,
@@ -167,6 +167,8 @@ export const resetUsers = async () => {
167167
await prisma.account_Code.deleteMany();
168168
await prisma.refund_Source.deleteMany();
169169
await prisma.index_Code.deleteMany();
170+
await prisma.document.deleteMany();
171+
await prisma.schedule_Slot.deleteMany();
170172
await prisma.event.deleteMany();
171173
await prisma.event_Type.deleteMany();
172174
await prisma.calendar.deleteMany();
@@ -613,19 +615,8 @@ export const createTestDesignReviewEvent = async () => {
613615
[], // shopIds
614616
[], // machineryIds
615617
[testWorkPackage.workPackageId], // workPackageIds
616-
[
617-
{
618-
startTime: new Date('2027-03-25T10:00:00'),
619-
endTime: new Date('2027-03-25T11:00:00'),
620-
allDay: false
621-
},
622-
{
623-
startTime: new Date('2027-03-25T11:00:00'),
624-
endTime: new Date('2027-03-25T12:00:00'),
625-
allDay: false
626-
}
627-
], // scheduleSlot - two 1-hour time slots
628-
undefined,
618+
[], // scheduleSlots - empty for confirmation events
619+
new Date('2027-03-25T10:00:00'), // initialDateScheduled - required for requiresConfirmation events
629620
teamType.teamTypeId, // team type id
630621
'https://docs.google.com/document/d/test-design-review-questions', // questionDocument
631622
'Campus Center Room 101', // location

0 commit comments

Comments
 (0)