Skip to content

Commit

Permalink
feat: complete other user service methods except update timetable
Browse files Browse the repository at this point in the history
  • Loading branch information
M7s7 committed Nov 1, 2023
1 parent a23f6cd commit 3b936e0
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions server/src/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import { SettingsDto, UserDTO, EventDto, TimetableDto } from './dto';
import { SettingsDto, UserDTO, EventDto, TimetableDto, ClassDto } from './dto';
import { PrismaService } from 'src/prisma/prisma.service';
import { v4 as uuidv4 } from 'uuid';

Expand Down Expand Up @@ -94,28 +94,60 @@ export class UserService {
_zid: string,
_name: string,
_selectedCourses: string[],
_selectedClasses: any[],
_selectedClasses: ClassDto[],
_createdEvents: EventDto[],
): Promise<void> {
try {
// Since we are using UUID to generate IDs, collisions are unlikely and upsert doesn't really make sense - use create instead
const newUUID = uuidv4();
const generatedId = uuidv4();

// Store timetables
await prisma.timetable.create({
data: {
id: newUUID,
id: generatedId,
name: _name,
selectedCourses: _selectedCourses,
zid: _zid,
},
});

// Store created events
// TBD: Upsert many - look for a better way to do this by firing 1 query rather than x queries
await prisma.event.createMany({
data: _createdEvents.map((e) => {
return { ...e, timetableId: generatedId };
}),
});

// Store classes
} catch (e) {}
await prisma.class.createMany({
data: _selectedClasses.map((c) => {
return { ...c, timetableId: generatedId };
}),
});

return Promise.resolve();
} catch (e) {
throw new Error(e);
}
}

editUserTimetable(zid: string, timetable: TimetableDto): void {}
// TBD: Need to think about how to do this one
async editUserTimetable(
_zid: string,
_timetable: TimetableDto,
): Promise<void> {}

async deleteUserTimetable(_timetableId: string): Promise<void> {
try {
await prisma.timetable.delete({
where: {
id: _timetableId,
},
});

return Promise.resolve();
} catch (e) {
throw new Error(e);
}
}
}

0 comments on commit 3b936e0

Please sign in to comment.