Refactor database queries.

This commit is contained in:
Mike Cao 2020-08-11 22:24:41 -07:00
parent a248f35db2
commit f4ca353b5c
24 changed files with 371 additions and 329 deletions

View file

@ -1,4 +1,4 @@
import { getAccount, deleteAccount } from 'lib/db';
import { getAccountById, deleteAccount } from 'lib/queries';
import { useAuth } from 'lib/middleware';
import { methodNotAllowed, ok, unauthorized } from 'lib/response';
@ -11,7 +11,7 @@ export default async (req, res) => {
if (req.method === 'GET') {
if (is_admin) {
const account = await getAccount({ user_id });
const account = await getAccountById(user_id);
return ok(res, account);
}

View file

@ -1,4 +1,4 @@
import { getAccount, updateAccount } from 'lib/db';
import { getAccountById, updateAccount } from 'lib/queries';
import { useAuth } from 'lib/middleware';
import { badRequest, methodNotAllowed, ok } from 'lib/response';
import { checkPassword, hashPassword } from 'lib/crypto';
@ -10,7 +10,7 @@ export default async (req, res) => {
const { current_password, new_password } = req.body;
if (req.method === 'POST') {
const account = await getAccount({ user_id });
const account = await getAccountById(user_id);
const valid = await checkPassword(current_password, account.password);
if (!valid) {