Add email to user
This commit is contained in:
parent
0233196276
commit
50ad684ad3
@ -17,12 +17,13 @@ model user {
|
|||||||
id Int @id @unique @default(autoincrement())
|
id Int @id @unique @default(autoincrement())
|
||||||
name String @unique
|
name String @unique
|
||||||
code String?
|
code String?
|
||||||
|
email String?
|
||||||
|
|
||||||
// TODO: Prüfen ob nötig, erstmal vorbereitet.
|
// TODO: Prüfen ob nötig, erstmal vorbereitet.
|
||||||
transactions transactions[]
|
transactions transactions[]
|
||||||
|
|
||||||
@@fulltext([name])
|
@@fulltext([name])
|
||||||
}
|
}
|
||||||
|
|
||||||
model transactions {
|
model transactions {
|
||||||
id Int @id @unique @default(autoincrement())
|
id Int @id @unique @default(autoincrement())
|
||||||
@ -62,3 +63,5 @@ model products {
|
|||||||
|
|
||||||
@@fulltext([name])
|
@@fulltext([name])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: migrate all ids to uuid?
|
||||||
|
@ -17,7 +17,6 @@ export function handlePrismaError(errorObj: any, res: Response, source: string)
|
|||||||
log.db.error(source, errorObj);
|
log.db.error(source, errorObj);
|
||||||
if (errorObj instanceof Prisma.PrismaClientKnownRequestError) {
|
if (errorObj instanceof Prisma.PrismaClientKnownRequestError) {
|
||||||
switch (errorObj.code) {
|
switch (errorObj.code) {
|
||||||
|
|
||||||
// P2002 -> "Unique constraint failed on the {constraint}"
|
// P2002 -> "Unique constraint failed on the {constraint}"
|
||||||
case 'P2002':
|
case 'P2002':
|
||||||
res.status(409).json({ status: 'ERROR', errorcode: 'DB_ERROR', message: 'The object needs to be unique', meta: errorObj.meta });
|
res.status(409).json({ status: 'ERROR', errorcode: 'DB_ERROR', message: 'The object needs to be unique', meta: errorObj.meta });
|
||||||
@ -44,4 +43,4 @@ export function handlePrismaError(errorObj: any, res: Response, source: string)
|
|||||||
|
|
||||||
export default prisma;
|
export default prisma;
|
||||||
|
|
||||||
//FIXME: https://www.prisma.io/docs/orm/prisma-client/special-fields-and-types/null-and-undefined
|
//FIXME: https://www.prisma.io/docs/orm/prisma-client/special-fields-and-types/null-and-undefined
|
||||||
|
@ -43,7 +43,7 @@ async function get(req: Request, res: Response) {
|
|||||||
});
|
});
|
||||||
res.status(200).json({ count, result });
|
res.status(200).json({ count, result });
|
||||||
} else {
|
} else {
|
||||||
res.status(404).json({ status: 'ERROR', errorcode: 'NOT_FOUND', message: 'Could not find specified object' });
|
res.status(404).json({ status: 'ERROR', errorcode: 'NOT_FOUND', message: 'Could not find specified user' });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@ -75,7 +75,7 @@ async function get(req: Request, res: Response) {
|
|||||||
});
|
});
|
||||||
res.status(200).json({ count, result });
|
res.status(200).json({ count, result });
|
||||||
} else {
|
} else {
|
||||||
res.status(404).json({ status: 'ERROR', errorcode: 'NOT_FOUND', message: 'Could not find specified object' });
|
res.status(404).json({ status: 'ERROR', errorcode: 'NOT_FOUND', message: 'Could not find any users' });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@ -97,6 +97,7 @@ async function post(req: Request, res: Response) {
|
|||||||
.create({
|
.create({
|
||||||
data: {
|
data: {
|
||||||
name: value.name,
|
name: value.name,
|
||||||
|
email: value.email,
|
||||||
code: value.code === '0000' ? null : value.code
|
code: value.code === '0000' ? null : value.code
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
@ -127,6 +128,7 @@ async function patch(req: Request, res: Response) {
|
|||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
name: value.name,
|
name: value.name,
|
||||||
|
email: value.email,
|
||||||
code: value.code === '0000' ? null : value.code
|
code: value.code === '0000' ? null : value.code
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
|
@ -22,6 +22,7 @@ const schema_get = validator
|
|||||||
// MARK: CREATE user
|
// MARK: CREATE user
|
||||||
const schema_post = validator.object({
|
const schema_post = validator.object({
|
||||||
name: validator.string().min(1).max(32).required(),
|
name: validator.string().min(1).max(32).required(),
|
||||||
|
email: validator.string().email().trim().required(),
|
||||||
code: validator.string().min(4).max(4).trim().regex(new RegExp(/^[0-9]+$/))
|
code: validator.string().min(4).max(4).trim().regex(new RegExp(/^[0-9]+$/))
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -30,9 +31,10 @@ const schema_patch = validator
|
|||||||
.object({
|
.object({
|
||||||
id: validator.number().positive().precision(0).required(),
|
id: validator.number().positive().precision(0).required(),
|
||||||
name: validator.string().min(1).max(32),
|
name: validator.string().min(1).max(32),
|
||||||
|
email: validator.string().email().trim(),
|
||||||
code: validator.string().min(4).max(4).trim().regex(new RegExp(/^[0-9]+$/))
|
code: validator.string().min(4).max(4).trim().regex(new RegExp(/^[0-9]+$/))
|
||||||
})
|
})
|
||||||
.or('name', 'code');
|
.or('name', 'email', 'code');
|
||||||
|
|
||||||
// MARK: DELETE user
|
// MARK: DELETE user
|
||||||
const schema_del = validator.object({
|
const schema_del = validator.object({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user