This commit is contained in:
+13
-6
@@ -826,10 +826,9 @@ authRoutes.post('/instructor/students', authRequired, async (c) => {
|
|||||||
|
|
||||||
const email = body.data.email.toLowerCase()
|
const email = body.data.email.toLowerCase()
|
||||||
const existingUser = await findUserByEmail(email)
|
const existingUser = await findUserByEmail(email)
|
||||||
if (existingUser) return c.json({ error: 'email_already_registered' }, 409)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const user = await createManagedUser({
|
const user = existingUser ?? await createManagedUser({
|
||||||
email,
|
email,
|
||||||
password: body.data.password,
|
password: body.data.password,
|
||||||
name: body.data.name,
|
name: body.data.name,
|
||||||
@@ -839,17 +838,25 @@ authRoutes.post('/instructor/students', authRequired, async (c) => {
|
|||||||
licenseCode: body.data.licenseCode,
|
licenseCode: body.data.licenseCode,
|
||||||
})
|
})
|
||||||
|
|
||||||
await prisma.userAppRole.create({
|
await prisma.userAppRole.upsert({
|
||||||
data: {
|
where: {
|
||||||
|
userId_appKey_roleCode: {
|
||||||
|
userId: user.id,
|
||||||
|
appKey: 'LMS',
|
||||||
|
roleCode: 'STUDENT',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
create: {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
appKey: 'LMS',
|
appKey: 'LMS',
|
||||||
roleCode: 'STUDENT',
|
roleCode: 'STUDENT',
|
||||||
assignedById: instructor.id,
|
assignedById: instructor.id,
|
||||||
},
|
},
|
||||||
|
update: {},
|
||||||
})
|
})
|
||||||
|
|
||||||
const createdUser = await findUserById(user.id)
|
const resolvedUser = await findUserById(user.id)
|
||||||
return c.json({ user: userResponse(createdUser ?? user) }, 201)
|
return c.json({ user: userResponse(resolvedUser ?? user) }, existingUser ? 200 : 201)
|
||||||
} catch {
|
} catch {
|
||||||
return c.json({ error: 'user_create_failed' }, 400)
|
return c.json({ error: 'user_create_failed' }, 400)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user