0
0
Fork 0

ログインできた

This commit is contained in:
Xeltica 2020-08-04 14:38:26 +09:00
parent 326384957c
commit dfbc06f858
18 changed files with 853 additions and 167 deletions

23
src/users.ts Normal file
View file

@ -0,0 +1,23 @@
import { User } from './models/entities/user';
import { Users } from './models';
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 deleteUser = async (username: string, host: string): Promise<void> => {
await Users.delete({ username, host });
};
export const getUserCount = (): Promise<number> => {
return Users.count();
};