Fix database model associations and update API route

This commit is contained in:
newtbot
2024-01-27 20:15:29 +08:00
parent 6190cb63cd
commit d491750916
14 changed files with 61 additions and 164 deletions

View File

@ -30,7 +30,7 @@ async function getTokenByToken(token) {
return token;
}
async function addToken(userId, permission, expiry) {
async function addToken(userId, permission, isKey ,expiry) {
let uuid = await generateUUID();
let hashtoken = await hash(uuid);
//console.log("user id", userId);
@ -41,6 +41,7 @@ async function addToken(userId, permission, expiry) {
userid: userId,
token: hashtoken,
permission: permission,
isKey: isKey,
expiration: expiry,
});
@ -48,4 +49,16 @@ async function addToken(userId, permission, expiry) {
return token.id + "-" + uuid;
}
module.exports = { addToken, getTokenByToken };
async function checkToken(id) {
let tokenRes = await tokenModel.findOne(
{
where: {
userid: id,
}
}
);
return tokenRes;
}
module.exports = { addToken, getTokenByToken , checkToken};