フォルダ分け
This commit is contained in:
parent
046351a8fa
commit
d20ac2c507
10 changed files with 21 additions and 21 deletions
28
src/functions/users.ts
Normal file
28
src/functions/users.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { User } from '../models/entities/user';
|
||||
import { Users } from '../models';
|
||||
import { DeepPartial } from 'typeorm';
|
||||
|
||||
export const getUser = (username: string, host: string): Promise<User | undefined> => {
|
||||
return Users.findOne({ username, host });
|
||||
};
|
||||
|
||||
export const upsertUser = async (username: string, host: string, token: string): Promise<void> => {
|
||||
const u = await getUser(username, host);
|
||||
if (u) {
|
||||
await Users.update({ username, host }, { token });
|
||||
} else {
|
||||
await Users.insert({ username, host, token });
|
||||
}
|
||||
};
|
||||
|
||||
export const updateUser = async (username: string, host: string, record: DeepPartial<User>): Promise<void> => {
|
||||
await Users.update({ username, host }, record);
|
||||
};
|
||||
|
||||
export const deleteUser = async (username: string, host: string): Promise<void> => {
|
||||
await Users.delete({ username, host });
|
||||
};
|
||||
|
||||
export const getUserCount = (): Promise<number> => {
|
||||
return Users.count();
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue