From e233708498cf144a7672e8c5dad5e6fbf29f5eee Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Wed, 4 Sep 2024 13:50:55 -0700 Subject: [PATCH] proponent related submissions dropdown added --- app/src/controllers/submission.ts | 9 ++++-- app/src/routes/v1/submission.ts | 10 ++++-- app/src/services/submission.ts | 14 -------- .../housing/enquiry/EnquiryIntakeForm.vue | 32 +++++++++++++++---- 4 files changed, 39 insertions(+), 26 deletions(-) diff --git a/app/src/controllers/submission.ts b/app/src/controllers/submission.ts index 74a3d842..633fbd5b 100644 --- a/app/src/controllers/submission.ts +++ b/app/src/controllers/submission.ts @@ -286,9 +286,12 @@ const controller = { getActivityIds: async (req: Request, res: Response, next: NextFunction) => { try { - const response = await submissionService.getActivityIds(); - - res.status(200).json(response); + let response = await submissionService.getSubmissions(); + if (req.currentAuthorization?.attributes.includes('scope:self')) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + response = response.filter((x) => x?.submittedBy === getCurrentUsername(req.currentContext)); + } + res.status(200).json(response.map((x) => x.activityId)); } catch (e: unknown) { next(e); } diff --git a/app/src/routes/v1/submission.ts b/app/src/routes/v1/submission.ts index f8b6af35..48dd3c5f 100644 --- a/app/src/routes/v1/submission.ts +++ b/app/src/routes/v1/submission.ts @@ -23,9 +23,13 @@ router.get( ); /** Get a list of all the activityIds */ -router.get('/activityIds', (req: Request, res: Response, next: NextFunction): void => { - submissionController.getActivityIds(req, res, next); -}); +router.get( + '/activityIds', + hasAuthorization(Resource.SUBMISSION, Action.READ), + (req: Request, res: Response, next: NextFunction): void => { + submissionController.getActivityIds(req, res, next); + } +); /** Search submissions */ router.get( diff --git a/app/src/services/submission.ts b/app/src/services/submission.ts index c53787f3..aeefb13c 100644 --- a/app/src/services/submission.ts +++ b/app/src/services/submission.ts @@ -28,20 +28,6 @@ function chefsAxios(formId: string, options: AxiosRequestConfig = {}): AxiosInst } const service = { - /** - * @function getActivityIds - * Gets a list of activity IDs - * @returns {Promise} The result of running the findMany operation - */ - getActivityIds: async () => { - try { - const result = await prisma.submission.findMany({ select: { activity_id: true } }); - return result.map((x) => x.activity_id); - } catch (e: unknown) { - throw e; - } - }, - /** * @function createSubmission * Creates a new submission diff --git a/frontend/src/components/housing/enquiry/EnquiryIntakeForm.vue b/frontend/src/components/housing/enquiry/EnquiryIntakeForm.vue index b021fb63..24b1720e 100644 --- a/frontend/src/components/housing/enquiry/EnquiryIntakeForm.vue +++ b/frontend/src/components/housing/enquiry/EnquiryIntakeForm.vue @@ -6,7 +6,15 @@ import { useRouter } from 'vue-router'; import { object, string } from 'yup'; import BackButton from '@/components/common/BackButton.vue'; -import { Dropdown, InputMask, InputText, RadioList, StepperNavigation, TextArea } from '@/components/form'; +import { + EditableDropdown, + Dropdown, + InputMask, + InputText, + RadioList, + StepperNavigation, + TextArea +} from '@/components/form'; import CollectionDisclaimer from '@/components/housing/CollectionDisclaimer.vue'; import EnquiryIntakeConfirmation from '@/components/housing/enquiry/EnquiryIntakeConfirmation.vue'; import { Button, Card, Divider, useConfirm, useToast } from '@/lib/primevue'; @@ -20,6 +28,7 @@ import { IntakeFormCategory, IntakeStatus } from '@/utils/enums/housing'; import { confirmationTemplate } from '@/utils/templates'; import type { Ref } from 'vue'; +import type { IInputEvent } from '@/interfaces'; const { formUpdated, stopAutoSave } = useAutoSave(async () => { const values = formRef.value?.values; @@ -47,7 +56,9 @@ const { getConfig } = storeToRefs(useConfigStore()); // State const assignedActivityId: Ref = ref(undefined); const editable: Ref = ref(true); +const filteredProjectActivityIds: Ref> = ref([]); const formRef: Ref | null> = ref(null); +const projectActivityIds: Ref> = ref([]); const validationErrors: Ref = ref([]); // Form validation schema @@ -222,8 +233,15 @@ async function loadEnquiry(enquiryId: string) { }); } -onBeforeMount(() => { +function onRelatedActivityInput(e: IInputEvent) { + filteredProjectActivityIds.value = projectActivityIds.value.filter((id) => + id.toUpperCase().includes(e.target.value.toUpperCase()) + ); +} + +onBeforeMount(async () => { if (props.enquiryId) loadEnquiry(props.enquiryId); + projectActivityIds.value = filteredProjectActivityIds.value = (await submissionService.getActivityIds()).data; }); async function emailConfirmation(activityId: string) { @@ -393,12 +411,14 @@ async function checkActivityIdValidity(event: Event) {