All files / server/api/auth profile.put.ts

100% Statements 18/18
88.88% Branches 8/9
100% Functions 0/0
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 191x 4x 4x 4x 4x 4x 1x 1x 1x 4x 2x 2x 2x 1x 1x 1x 1x 1x  
export default defineEventHandler(async event => {
    const user = await requireUser(event);
    const body = await readBody(event);
    const firstName = String(body.firstName || '').trim();
    const lastName = String(body.lastName || '').trim();
    if (!firstName || !lastName) throw createError({
        statusCode: 400,
        statusMessage: 'Le prénom et le nom sont obligatoires'
    });
    if (firstName.length > 80 || lastName.length > 80) throw createError({
        statusCode: 400,
        statusMessage: 'Le prénom et le nom ne peuvent pas dépasser 80 caractères'
    });
    const db = database(event);
    await ready(db);
    await db.prepare('UPDATE users SET first_name=?,last_name=? WHERE id=?').bind(firstName, lastName, user.id).run();
    return {user: {firstName, lastName}}
});