add group creation

This commit is contained in:
2026-01-07 10:25:33 +01:00
parent 090b3c10d1
commit 624e62822c
12 changed files with 330 additions and 94 deletions

View File

@@ -80,25 +80,25 @@ class DB {
* @param mail: string
* @returns created user
*/
public async createUser(mail: string): Promise<User> {
const user: User = await this.instance`
public async createUser(mail: string): Promise<User | null> {
const user: User[] = await this.instance`
INSERT INTO users (mail) VALUES (${mail})
RETURNING *
`;
return user;
return user[0] ?? null;
}
/**
* Get user by mail
* @param mail: string
* @returns user object or undefined
* @returns user object or null
*/
public async getUserByMail(mail: string): Promise<User | undefined> {
const user: User = await this.instance`
public async getUserByMail(mail: string): Promise<User | null> {
const user: User[] = await this.instance`
SELECT * FROM users WHERE mail = ${mail}
`;
return user;
return user[0] ?? null;
}
/* GROUPS */
@@ -109,25 +109,26 @@ class DB {
* @param mail: string
* @returns object with id of the created group
*/
public async createGroup( {name, mail}: {name: string, mail: string}): Promise<Group> {
public async createGroup( {name, mail}: {name: string, mail: string}): Promise<Group | null> {
const code = Math.random().toString(36).substring(2, 8).toUpperCase();
const group: Group = await this.instance`
const group: Group[] = await this.instance`
INSERT INTO groups (code, name, mail) VALUES (${code}, ${name}, ${mail})
RETURNING *
`;
return group;
console.log('Created group:', group);
return group[0] ?? null;
};
/**
* Get group by ID
* @param id: string
* @returns group object or undefined
* @returns group object or null
*/
public async getGroupByCode(code: string): Promise<Group | undefined> {
const group: Group | undefined = await this.instance`
public async getGroupByCode(code: string): Promise<Group | null> {
const group: Group[] = await this.instance`
SELECT * FROM groups WHERE code = ${code}
`;
return group;
return group[0] ?? null;
}
/* GROUP MEMBER */