update admin login api to return admin data
This commit is contained in:
@@ -35,7 +35,10 @@ import {
|
||||
adminUpdateRequestSchema,
|
||||
adminVerifyRequestSchema,
|
||||
} from "@/modules/admin/admin.schemas";
|
||||
import type { AdminResponse } from "@/modules/admin/admin.types";
|
||||
import type {
|
||||
AdminLoginResponse,
|
||||
AdminResponse,
|
||||
} from "@/modules/admin/admin.types";
|
||||
import * as dateFns from "date-fns";
|
||||
import { Router, type Request, type Response } from "express";
|
||||
import { ulid } from "ulid";
|
||||
@@ -153,13 +156,14 @@ export class AdminController extends Controller {
|
||||
|
||||
return res.status(200).json({
|
||||
data: {
|
||||
admin: this.mapper.mapEntityToResponse(admin),
|
||||
access_token: access.token,
|
||||
access_token_expires_at: access.expiresAt,
|
||||
refresh_token: refresh.token,
|
||||
refresh_token_expires_at: refresh.expiresAt,
|
||||
},
|
||||
errors: null,
|
||||
} satisfies SingleResponse);
|
||||
} satisfies SingleResponse<AdminLoginResponse>);
|
||||
}
|
||||
|
||||
async list(req: Request, res: Response) {
|
||||
@@ -232,6 +236,15 @@ export class AdminController extends Controller {
|
||||
} satisfies SingleResponse<AdminResponse>);
|
||||
}
|
||||
|
||||
async viewMe(_req: Request, res: Response) {
|
||||
const req = _req as Request & AdminRequestPlugin;
|
||||
|
||||
return res.status(200).json({
|
||||
data: this.mapper.mapEntityToResponse(req.admin),
|
||||
errors: null,
|
||||
} satisfies SingleResponse<AdminResponse>);
|
||||
}
|
||||
|
||||
async update(req: Request, res: Response) {
|
||||
const parseParamsResult = adminParamsSchema.safeParse(req.params);
|
||||
if (!parseParamsResult.success) {
|
||||
@@ -585,6 +598,7 @@ export class AdminController extends Controller {
|
||||
);
|
||||
router.post("/login", createOrmContextMiddleware, this.login.bind(this));
|
||||
router.get("/", createOrmContextMiddleware, this.list.bind(this));
|
||||
router.get("/@me", createOrmContextMiddleware, this.viewMe.bind(this));
|
||||
router.get("/:id", createOrmContextMiddleware, this.view.bind(this));
|
||||
router.put(
|
||||
"/:id",
|
||||
|
||||
@@ -31,3 +31,11 @@ export type AdminResponse = {
|
||||
created_at: Date;
|
||||
updated_at: Date;
|
||||
};
|
||||
|
||||
export type AdminLoginResponse = {
|
||||
admin: AdminResponse;
|
||||
access_token: string;
|
||||
access_token_expires_at: Date;
|
||||
refresh_token: string;
|
||||
refresh_token_expires_at: Date;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user