mirror of
https://github.com/wasp-lang/open-saas.git
synced 2025-03-29 11:12:19 +01:00
Patch update user bug
This commit is contained in:
parent
496480509a
commit
e1a4ee8ab0
@ -357,13 +357,13 @@ action stripePayment {
|
||||
entities: [User]
|
||||
}
|
||||
|
||||
action updateCurrentUser {
|
||||
fn: import { updateCurrentUser } from "@src/server/actions.js",
|
||||
action updateCurrentUserLastActiveTimestamp {
|
||||
fn: import { updateCurrentUserLastActiveTimestamp } from "@src/server/actions.js",
|
||||
entities: [User]
|
||||
}
|
||||
|
||||
action updateUserById {
|
||||
fn: import { updateUserById } from "@src/server/actions.js",
|
||||
action updateIsUserAdminById {
|
||||
fn: import { updateIsUserAdminById } from "@src/server/actions.js",
|
||||
entities: [User]
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { useAuth } from 'wasp/client/auth';
|
||||
import { updateCurrentUser } from 'wasp/client/operations';
|
||||
import { updateCurrentUserLastActiveTimestamp } from 'wasp/client/operations';
|
||||
import './Main.css';
|
||||
import AppNavBar from './components/AppNavBar';
|
||||
import { useMemo, useEffect, ReactNode } from 'react';
|
||||
@ -26,7 +26,7 @@ export default function App({ children }: { children: ReactNode }) {
|
||||
const lastSeenAt = new Date(user.lastActiveTimestamp);
|
||||
const today = new Date();
|
||||
if (today.getTime() - lastSeenAt.getTime() > 5 * 60 * 1000) {
|
||||
updateCurrentUser({ lastActiveTimestamp: today });
|
||||
updateCurrentUserLastActiveTimestamp({ lastActiveTimestamp: today });
|
||||
}
|
||||
}
|
||||
}, [user]);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { updateUserById, useQuery, getPaginatedUsers } from 'wasp/client/operations';
|
||||
import { updateIsUserAdminById, useQuery, getPaginatedUsers } from 'wasp/client/operations';
|
||||
import { useState, useEffect } from 'react';
|
||||
import SwitcherOne from './SwitcherOne';
|
||||
import Loader from '../common/Loader';
|
||||
@ -218,7 +218,7 @@ const UsersTable = () => {
|
||||
</div>
|
||||
<div className='col-span-1 flex items-center'>
|
||||
<div className='text-sm text-black dark:text-white'>
|
||||
<SwitcherOne user={user} updateUserById={updateUserById} />
|
||||
<SwitcherOne user={user} updateUserById={updateIsUserAdminById} />
|
||||
</div>
|
||||
</div>
|
||||
<div className='col-span-1 flex items-center'>
|
||||
|
@ -3,8 +3,8 @@ import { HttpError } from 'wasp/server';
|
||||
import {
|
||||
type GenerateGptResponse,
|
||||
type StripePayment,
|
||||
type UpdateCurrentUser,
|
||||
type UpdateUserById,
|
||||
type UpdateCurrentUserLastActiveTimestamp,
|
||||
type UpdateIsUserAdminById,
|
||||
type CreateTask,
|
||||
type DeleteTask,
|
||||
type UpdateTask,
|
||||
@ -286,23 +286,23 @@ export const deleteTask: DeleteTask<Pick<Task, 'id'>, Task> = async ({ id }, con
|
||||
return task;
|
||||
};
|
||||
|
||||
export const updateUserById: UpdateUserById<{ id: number; data: Partial<User> }, User> = async (
|
||||
export const updateIsUserAdminById: UpdateIsUserAdminById<{ id: number; data: Pick<User, 'isAdmin'> }, User> = async (
|
||||
{ id, data },
|
||||
context
|
||||
) => {
|
||||
if (!context.user) {
|
||||
throw new HttpError(401);
|
||||
}
|
||||
|
||||
if (!context.user.isAdmin) {
|
||||
throw new HttpError(403);
|
||||
}
|
||||
|
||||
const updatedUser = await context.entities.User.update({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
data,
|
||||
data: {
|
||||
isAdmin: data.isAdmin,
|
||||
},
|
||||
});
|
||||
|
||||
return updatedUser;
|
||||
@ -333,15 +333,15 @@ export const createFile: CreateFile<fileArgs, File> = async ({ fileType, name },
|
||||
});
|
||||
};
|
||||
|
||||
export const updateCurrentUser: UpdateCurrentUser<Partial<User>, User> = async (user, context) => {
|
||||
if (!context.user) {
|
||||
throw new HttpError(401);
|
||||
}
|
||||
|
||||
return context.entities.User.update({
|
||||
where: {
|
||||
id: context.user.id,
|
||||
},
|
||||
data: user,
|
||||
});
|
||||
};
|
||||
export const updateCurrentUserLastActiveTimestamp: UpdateCurrentUserLastActiveTimestamp<Pick<User, 'lastActiveTimestamp'>, User> =
|
||||
async ({ lastActiveTimestamp }, context) => {
|
||||
if (!context.user) {
|
||||
throw new HttpError(401);
|
||||
}
|
||||
return context.entities.User.update({
|
||||
where: {
|
||||
id: context.user.id,
|
||||
},
|
||||
data: { lastActiveTimestamp },
|
||||
});
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user