Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed projectTabs adminUserId to true but still not updating in Database #1605

Merged
merged 7 commits into from
Jun 14, 2024
19 changes: 13 additions & 6 deletions src/server/adminJs/tabs/projectsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,13 +650,15 @@ export const projectsTab = {
},
},
adminUserId: {
type: 'Number',
isVisible: {
list: true,
filter: false,
show: true,
edit: false,
edit: true,
new: false,
},
position: 1,
},
contacts: {
isVisible: {
Expand Down Expand Up @@ -706,9 +708,7 @@ export const projectsTab = {
totalTraceDonations: {
isVisible: { list: false, filter: false, show: true, edit: true },
},
admin: {
isVisible: { list: false, filter: false, show: true, edit: true },
},

description: {
isVisible: {
list: false,
Expand All @@ -728,6 +728,7 @@ export const projectsTab = {
show: true,
edit: false,
},

components: {
show: adminJs.bundle('./components/ClickableLink'),
},
Expand Down Expand Up @@ -883,6 +884,7 @@ export const projectsTab = {
edit: {
isAccessible: ({ currentAdmin }) =>
canAccessProjectAction({ currentAdmin }, ResourceActions.EDIT),

before: async (request: AdminJsRequestInterface) => {
const { verified, reviewStatus } = request.payload;
const statusChanges: string[] = [];
Expand Down Expand Up @@ -945,8 +947,13 @@ export const projectsTab = {
NOTIFICATIONS_EVENT_NAMES.PROJECT_NOT_REVIEWED,
);
}
if (Number(request?.payload?.admin) !== project?.adminUserId) {

if (
Number(request?.payload?.adminUserId) !== project?.adminUserId
) {
const newID = request?.payload?.adminUserId;
request.payload.adminChanged = true;
request.payload.newAdminId = newID;
}

// We put these status changes in payload, so in after hook we would know to send notification for users
Expand All @@ -966,7 +973,7 @@ export const projectsTab = {
if (project) {
if (request?.record?.params?.adminChanged) {
const adminUser = await User.findOne({
where: { id: project.adminUserId },
where: { id: request?.record?.params?.newAdminId },
});
project.adminUser = adminUser!;
await project.save();
Expand Down
Loading