Skip to content

Commit ba135e5

Browse files
committed
feat: update return type in checkUsernameExists api call to boolean
1 parent 22c33d2 commit ba135e5

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

apps/api/src/users/users.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class UsersService {
1717
private readonly groupsService: GroupsService
1818
) {}
1919

20-
async checkUsernameExists(username: string, { ability }: EntityOperationOptions = {}) {
20+
async checkUsernameExists(username: string, { ability }: EntityOperationOptions = {}): Promise<{ success: boolean }> {
2121
const user = await this.userModel.findFirst({
2222
include: { groups: true },
2323
omit: {
@@ -26,9 +26,9 @@ export class UsersService {
2626
where: { AND: [accessibleQuery(ability, 'read', 'User'), { username }] }
2727
});
2828
if (!user) {
29-
return false;
29+
return { success: false };
3030
}
31-
return user;
31+
return { success: true };
3232
}
3333

3434
async count(

apps/web/src/routes/_app/admin/users/create.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ const RouteComponent = () => {
2222

2323
const handleSubmit = async (data: CreateUserData) => {
2424
// check if username exists
25-
const existingUsername = await axios.get(`/v1/users/check-username/${encodeURIComponent(data.username)}`);
25+
const existingUsername = await axios.get<{ success: boolean }>(
26+
`/v1/users/check-username/${encodeURIComponent(data.username)}`
27+
);
2628

27-
if (existingUsername.data !== false) {
29+
if (existingUsername.data.success === true) {
2830
notification.addNotification({
2931
type: 'error',
3032
message: t('common.usernameExists')
3133
});
3234
} else {
33-
createUserMutation.mutate({ data });
35+
void createUserMutation.mutateAsync({ data });
3436

3537
void navigate({ to: '..' });
3638
}

0 commit comments

Comments
 (0)