Accessing/changing another entity when performing a db action

I'm new to NodeJS, prisma and the likes and am having some trouble implementing an action.
When I create a Student, they need to get a number assigned to them.
If there are already 10 students in the class, the next created student should get number 11.
I'm not sure how to best do this.

This us my current code:
export const createStudent: CreateStudent<CreateStudentPayload, Student> = async (args, context) => {
    if (!context.user) {
        throw new HttpError(401);
    }

    return context.entities.Student.create({
        data: {
            name: args.name,
            number: 11,
            class: { connect: { teacherId: context.user.id }}
        }
    })
}


I tried calling the getClass query from the createStudent action and passing the cotext along, but it is not of the correct type.

Should I send along the classId from the frontend, even though the frontend does not need to know about it?
Should I just use the prismaClient and the full context over the wasp context?
Was this page helpful?