Initial Typescript models.

This commit is contained in:
Brian Cao 2022-11-15 13:21:14 -08:00
parent 04e9f06e93
commit 0aaba8cbd1
74 changed files with 1144 additions and 768 deletions

View file

@ -1,8 +1,23 @@
import { badRequest, hashPassword, methodNotAllowed, ok, unauthorized } from 'next-basics';
import { getUser, deleteUser, updateUser } from 'queries';
import { useAuth } from 'lib/middleware';
import { NextApiResponse } from 'next';
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
import { User } from 'interface/api/models';
export default async (req, res) => {
export interface UserReqeustQuery {
id: string;
}
export interface UserReqeustBody {
username: string;
password: string;
}
export default async (
req: NextApiRequestQueryBody<UserReqeustQuery, UserReqeustBody>,
res: NextApiResponse<User>,
) => {
await useAuth(req, res);
const {
@ -29,7 +44,7 @@ export default async (req, res) => {
const user = await getUser({ id });
const data = {};
const data: any = {};
if (password) {
data.password = hashPassword(password);

View file

@ -10,8 +10,23 @@ import {
} from 'next-basics';
import { allowQuery } from 'lib/auth';
import { TYPE_USER } from 'lib/constants';
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
import { NextApiResponse } from 'next';
import { User } from 'interface/api/models';
export default async (req, res) => {
export interface UserPasswordRequestQuery {
id: string;
}
export interface UserPasswordRequestBody {
current_password: string;
new_password: string;
}
export default async (
req: NextApiRequestQueryBody<UserPasswordRequestQuery, UserPasswordRequestBody>,
res: NextApiResponse<User>,
) => {
await useAuth(req, res);
const { current_password, new_password } = req.body;

View file

@ -2,8 +2,20 @@ import { ok, unauthorized, methodNotAllowed, badRequest, hashPassword } from 'ne
import { useAuth } from 'lib/middleware';
import { uuid } from 'lib/crypto';
import { createUser, getUser, getUsers } from 'queries';
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
import { NextApiResponse } from 'next';
import { User } from 'interface/api/models';
export default async (req, res) => {
export interface UsersRequestBody {
username: string;
password: string;
id: string;
}
export default async (
req: NextApiRequestQueryBody<UsersRequestBody>,
res: NextApiResponse<User[] | User>,
) => {
await useAuth(req, res);
const {