Skip to content

Commit e1a4ee8

Browse files
committed
Patch update user bug
1 parent 4964805 commit e1a4ee8

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

app/main.wasp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,13 @@ action stripePayment {
357357
entities: [User]
358358
}
359359

360-
action updateCurrentUser {
361-
fn: import { updateCurrentUser } from "@src/server/actions.js",
360+
action updateCurrentUserLastActiveTimestamp {
361+
fn: import { updateCurrentUserLastActiveTimestamp } from "@src/server/actions.js",
362362
entities: [User]
363363
}
364364

365-
action updateUserById {
366-
fn: import { updateUserById } from "@src/server/actions.js",
365+
action updateIsUserAdminById {
366+
fn: import { updateIsUserAdminById } from "@src/server/actions.js",
367367
entities: [User]
368368
}
369369

app/src/client/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useAuth } from 'wasp/client/auth';
2-
import { updateCurrentUser } from 'wasp/client/operations';
2+
import { updateCurrentUserLastActiveTimestamp } from 'wasp/client/operations';
33
import './Main.css';
44
import AppNavBar from './components/AppNavBar';
55
import { useMemo, useEffect, ReactNode } from 'react';
@@ -26,7 +26,7 @@ export default function App({ children }: { children: ReactNode }) {
2626
const lastSeenAt = new Date(user.lastActiveTimestamp);
2727
const today = new Date();
2828
if (today.getTime() - lastSeenAt.getTime() > 5 * 60 * 1000) {
29-
updateCurrentUser({ lastActiveTimestamp: today });
29+
updateCurrentUserLastActiveTimestamp({ lastActiveTimestamp: today });
3030
}
3131
}
3232
}, [user]);

app/src/client/admin/components/UsersTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { updateUserById, useQuery, getPaginatedUsers } from 'wasp/client/operations';
1+
import { updateIsUserAdminById, useQuery, getPaginatedUsers } from 'wasp/client/operations';
22
import { useState, useEffect } from 'react';
33
import SwitcherOne from './SwitcherOne';
44
import Loader from '../common/Loader';
@@ -218,7 +218,7 @@ const UsersTable = () => {
218218
</div>
219219
<div className='col-span-1 flex items-center'>
220220
<div className='text-sm text-black dark:text-white'>
221-
<SwitcherOne user={user} updateUserById={updateUserById} />
221+
<SwitcherOne user={user} updateUserById={updateIsUserAdminById} />
222222
</div>
223223
</div>
224224
<div className='col-span-1 flex items-center'>

app/src/server/actions.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { HttpError } from 'wasp/server';
33
import {
44
type GenerateGptResponse,
55
type StripePayment,
6-
type UpdateCurrentUser,
7-
type UpdateUserById,
6+
type UpdateCurrentUserLastActiveTimestamp,
7+
type UpdateIsUserAdminById,
88
type CreateTask,
99
type DeleteTask,
1010
type UpdateTask,
@@ -286,23 +286,23 @@ export const deleteTask: DeleteTask<Pick<Task, 'id'>, Task> = async ({ id }, con
286286
return task;
287287
};
288288

289-
export const updateUserById: UpdateUserById<{ id: number; data: Partial<User> }, User> = async (
289+
export const updateIsUserAdminById: UpdateIsUserAdminById<{ id: number; data: Pick<User, 'isAdmin'> }, User> = async (
290290
{ id, data },
291291
context
292292
) => {
293293
if (!context.user) {
294294
throw new HttpError(401);
295295
}
296-
297296
if (!context.user.isAdmin) {
298297
throw new HttpError(403);
299298
}
300-
301299
const updatedUser = await context.entities.User.update({
302300
where: {
303301
id,
304302
},
305-
data,
303+
data: {
304+
isAdmin: data.isAdmin,
305+
},
306306
});
307307

308308
return updatedUser;
@@ -333,15 +333,15 @@ export const createFile: CreateFile<fileArgs, File> = async ({ fileType, name },
333333
});
334334
};
335335

336-
export const updateCurrentUser: UpdateCurrentUser<Partial<User>, User> = async (user, context) => {
337-
if (!context.user) {
338-
throw new HttpError(401);
339-
}
340-
341-
return context.entities.User.update({
342-
where: {
343-
id: context.user.id,
344-
},
345-
data: user,
346-
});
347-
};
336+
export const updateCurrentUserLastActiveTimestamp: UpdateCurrentUserLastActiveTimestamp<Pick<User, 'lastActiveTimestamp'>, User> =
337+
async ({ lastActiveTimestamp }, context) => {
338+
if (!context.user) {
339+
throw new HttpError(401);
340+
}
341+
return context.entities.User.update({
342+
where: {
343+
id: context.user.id,
344+
},
345+
data: { lastActiveTimestamp },
346+
});
347+
};

0 commit comments

Comments
 (0)