From 4b8d3082933aa9d2483d561a4f4018e3a684eeba Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 18 Sep 2024 19:17:28 -0500 Subject: [PATCH] fix eslint --- .../CustomQfRoundMultiUpdateComponent.tsx | 4 +- .../tabs/components/ProjectCategories.tsx | 4 +- src/server/adminJs/tabs/projectsTab.ts | 63 ++++++++++--------- 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/server/adminJs/tabs/components/CustomQfRoundMultiUpdateComponent.tsx b/src/server/adminJs/tabs/components/CustomQfRoundMultiUpdateComponent.tsx index 644d6ad82..c86aa78ac 100644 --- a/src/server/adminJs/tabs/components/CustomQfRoundMultiUpdateComponent.tsx +++ b/src/server/adminJs/tabs/components/CustomQfRoundMultiUpdateComponent.tsx @@ -26,9 +26,7 @@ const RecordInput = ({ index, record, updateRecord, removeRecord }) => ( - updateRecord(index, 'matchingFund', e.target.value) - } + onChange={e => updateRecord(index, 'matchingFund', e.target.value)} required /> diff --git a/src/server/adminJs/tabs/components/ProjectCategories.tsx b/src/server/adminJs/tabs/components/ProjectCategories.tsx index 27a6e8893..5706131cb 100644 --- a/src/server/adminJs/tabs/components/ProjectCategories.tsx +++ b/src/server/adminJs/tabs/components/ProjectCategories.tsx @@ -14,7 +14,9 @@ const ProjectUpdates = props => {
-

{category.name || ''} - Id: {category.id}

+

+ {category.name || ''} - Id: {category.id} +

); diff --git a/src/server/adminJs/tabs/projectsTab.ts b/src/server/adminJs/tabs/projectsTab.ts index 3e8ad00dd..a61aedfa6 100644 --- a/src/server/adminJs/tabs/projectsTab.ts +++ b/src/server/adminJs/tabs/projectsTab.ts @@ -447,12 +447,12 @@ export const addProjectsToQfRound = async ( }; }; - export const extractCategoryIds = (payload: any) => { - if (!payload) return; - return Object.keys(payload) - .filter(key => key.startsWith('categoryIds.')) - .map(key => payload[key]); -} +export const extractCategoryIds = (payload: any) => { + if (!payload) return; + return Object.keys(payload) + .filter(key => key.startsWith('categoryIds.')) + .map(key => payload[key]); +}; export const addSingleProjectToQfRound = async ( context: AdminJsContextInterface, @@ -496,12 +496,11 @@ export const fillSocialProfileAndQfRounds: After< const adminJsBaseUrl = process.env.SERVER_URL; let categories; if (project) { - categories = await Category - .createQueryBuilder('category') - .innerJoin('category.projects', 'projects') - .where('projects.id = :id', { id: project.id }) - .orderBy('category.name', 'ASC') - .getMany(); + categories = await Category.createQueryBuilder('category') + .innerJoin('category.projects', 'projects') + .where('projects.id = :id', { id: project.id }) + .orderBy('category.name', 'ASC') + .getMany(); } response.record = { ...record, @@ -866,12 +865,11 @@ export const projectsTab = { components: { show: adminJs.bundle('./components/ProjectCategories'), }, - availableValues: async (_record) => { - const categories = await Category - .createQueryBuilder('category') + availableValues: async _record => { + const categories = await Category.createQueryBuilder('category') .where('category.isActive = :isActive', { isActive: true }) .orderBy('category.name', 'ASC') - .getMany(); + .getMany(); return categories.map(category => ({ value: category.id, label: `${category.id} - ${category.name}`, @@ -971,18 +969,20 @@ export const projectsTab = { isVisible: false, isAccessible: ({ currentAdmin }) => canAccessProjectAction({ currentAdmin }, ResourceActions.NEW), - before: async (request) => { + before: async request => { if (request.payload.categories) { - request.payload.categories = (request.payload.categories as string[]).map(id => ({ id: parseInt(id, 10) })); + request.payload.categories = ( + request.payload.categories as string[] + ).map(id => ({ id: parseInt(id, 10) })); } return request; }, - after: async (response) => { - const { record, request } = response; + after: async response => { + const { request } = response; const project = await Project.findOne({ where: { id: request?.record?.id }, }); - const categoryIds = extractCategoryIds(request.record.params); + const categoryIds = extractCategoryIds(request.record.params); await saveCategories(project!, categoryIds || []); return response; @@ -1016,10 +1016,13 @@ export const projectsTab = { const project = await findProjectById(Number(request.payload.id)); if (project) { - await Category.query(` + await Category.query( + ` DELETE FROM project_categories_category WHERE "projectId" = $1 - `, [project.id]); + `, + [project.id], + ); } if ( @@ -1084,7 +1087,7 @@ export const projectsTab = { // We put these status changes in payload, so in after hook we would know to send notification for users request.payload.statusChanges = statusChanges.join(','); } - + return request; }, after: async ( @@ -1222,7 +1225,7 @@ export const projectsTab = { }); } } - const categoryIds = extractCategoryIds(request.record.params); + const categoryIds = extractCategoryIds(request.record.params); await Promise.all([ refreshUserProjectPowerView(), @@ -1429,13 +1432,15 @@ async function saveCategories(project: Project, categoryIds?: string[]) { if (!project) return; if (!categoryIds || categoryIds?.length === 0) return; - await Category.query(` + await Category.query( + ` DELETE FROM project_categories_category WHERE "projectId" = $1 - `, [project.id]); + `, + [project.id], + ); - const categories = await Category - .createQueryBuilder('category') + const categories = await Category.createQueryBuilder('category') .where('category.id IN (:...ids)', { ids: categoryIds }) .getMany();