Fix upsert: create professional record if none exists
PATCH /professionals/me now works for first-time submissions. Creates the record with pro_state=1 if user has no professional entry. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
ce769dfe8d
commit
d551739d0c
@@ -68,8 +68,12 @@ export class ProfessionalsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async upsert(userId: string, data: any) {
|
async upsert(userId: string, data: any) {
|
||||||
const prof = await this.prisma.professionals.findUnique({ where: { user_id: userId } });
|
const existing = await this.prisma.professionals.findUnique({ where: { user_id: userId } });
|
||||||
if (!prof) throw new NotFoundException('Debes solicitar ser profesional primero');
|
|
||||||
|
if (!existing) {
|
||||||
|
await this.prisma.users.update({ where: { id: userId }, data: { pro_state: 1 } });
|
||||||
|
return this.prisma.professionals.create({ data: { user_id: userId, ...data } });
|
||||||
|
}
|
||||||
|
|
||||||
return this.prisma.professionals.update({ where: { user_id: userId }, data });
|
return this.prisma.professionals.update({ where: { user_id: userId }, data });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user