Skip to content

Commit

Permalink
release: v0.3.2 (fix lastLoginAt schema error)
Browse files Browse the repository at this point in the history
  • Loading branch information
moeakwak committed May 11, 2024
1 parent fa78ad6 commit ad9d8f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/app/(panel)/admin/users/users-table.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import * as React from "react";
import { type UserReadAdmin, UserReadAdminSchema } from "@/schema/user.schema";
import { type UserReadAdmin, UserReadAdminSchema, UserReadAdminWithLastLoginSchema } from "@/schema/user.schema";
import { api } from "@/trpc/react";
import { popupEditPasswordForm } from "@/app/(panel)/_components/edit-password-popup";
import { DataTable, type DataTableDropdownAction } from "@/components/data-table";
Expand Down Expand Up @@ -102,7 +102,7 @@ export function UsersTable() {
<DataTable
data={getAllUserQuery.data ?? []}
filterSearchField={"username"}
schema={UserReadAdminSchema}
schema={UserReadAdminWithLastLoginSchema}
rowDropdownActions={rowDropdownActions}
defaultPageSize={30}
/>
Expand Down
7 changes: 5 additions & 2 deletions src/schema/user.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ export type UserCreate = z.infer<typeof UserCreateSchema>;

export const UserReadAdminSchema = UserSchema.omit({
hashedPassword: true,
}).merge(
});

export const UserReadAdminWithLastLoginSchema = UserReadAdminSchema.merge(
z.object({
lastLoginAt: z
.string()
.nullable()
.nullish()
.transform((v) => (v ? new Date(v) : null)),
}),
);

export type UserReadAdmin = z.infer<typeof UserReadAdminSchema>;
export const UserReadSchema = UserReadAdminSchema.omit({
comment: true,
Expand Down
3 changes: 2 additions & 1 deletion src/server/api/routers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
UserCreateSchema,
UserRoles,
UserUpdateAdminSchema,
UserReadAdminWithLastLoginSchema,
} from "@/schema/user.schema";
import { hashPassword } from "@/lib/password";
import { writeUserCreateEventLog } from "@/server/actions/write-event-log";
Expand Down Expand Up @@ -126,7 +127,7 @@ export const userRouter = createTRPCRouter({
.from(users)
.leftJoin(sessions, eq(sessions.userId, users.id))
.groupBy(users.id);
return UserReadAdminSchema.array().parse(results);
return UserReadAdminWithLastLoginSchema.array().parse(results);
}),

editInstanceAbilities: adminProcedure
Expand Down

0 comments on commit ad9d8f3

Please sign in to comment.