From 45542255763410d6992d1c3122f443a1213d28ca Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Fri, 23 Aug 2024 10:25:41 -0700 Subject: [PATCH] Change related enquiry --- app/src/controllers/submission.ts | 10 ++++++ app/src/routes/v1/submission.ts | 5 +++ app/src/services/submission.ts | 14 ++++++++ .../housing/enquiry/EnquiryForm.vue | 23 ++++++++++-- frontend/src/services/submissionService.ts | 8 +++++ .../src/views/housing/enquiry/EnquiryView.vue | 36 ++++++++++++++----- 6 files changed, 85 insertions(+), 11 deletions(-) diff --git a/app/src/controllers/submission.ts b/app/src/controllers/submission.ts index 9fe8d700..0d61f999 100644 --- a/app/src/controllers/submission.ts +++ b/app/src/controllers/submission.ts @@ -294,6 +294,16 @@ const controller = { return submissionData; }, + getActivityIds: async (req: Request, res: Response, next: NextFunction) => { + try { + const response = await submissionService.getActivityIds(); + + res.status(200).json(response); + } catch (e: unknown) { + next(e); + } + }, + createDraft: async (req: Request, res: Response, next: NextFunction) => { try { // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/app/src/routes/v1/submission.ts b/app/src/routes/v1/submission.ts index be2477aa..fbe2368a 100644 --- a/app/src/routes/v1/submission.ts +++ b/app/src/routes/v1/submission.ts @@ -13,6 +13,11 @@ router.get('/', (req: Request, res: Response, next: NextFunction): void => { submissionController.getSubmissions(req, res, next); }); +/** Get a list of all the activityIds */ +router.get('/activityIds', (req: Request, res: Response, next: NextFunction): void => { + submissionController.getActivityIds(req, res, next); +}); + /** Search submissions */ router.get( '/search', diff --git a/app/src/services/submission.ts b/app/src/services/submission.ts index d4a78c8a..1e01d432 100644 --- a/app/src/services/submission.ts +++ b/app/src/services/submission.ts @@ -27,6 +27,20 @@ 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/EnquiryForm.vue b/frontend/src/components/housing/enquiry/EnquiryForm.vue index e709bbfa..6af36fec 100644 --- a/frontend/src/components/housing/enquiry/EnquiryForm.vue +++ b/frontend/src/components/housing/enquiry/EnquiryForm.vue @@ -15,9 +15,9 @@ import { TextArea } from '@/components/form'; import { Button, Message, useToast } from '@/lib/primevue'; -import { enquiryService, userService } from '@/services'; +import { enquiryService, submissionService, userService } from '@/services'; import { useEnquiryStore } from '@/store'; -import { Regex } from '@/utils/enums/application'; +import { BasicResponse, Regex } from '@/utils/enums/application'; import { IntakeStatus } from '@/utils/enums/housing'; import { APPLICATION_STATUS_LIST, @@ -47,10 +47,15 @@ const props = withDefaults(defineProps(), { editable: true }); +// Emit +const emit = defineEmits(['enquiryForm:saved']); + // State const assigneeOptions: Ref> = ref([]); const editable: Ref = ref(props.editable); +const filteredProjectActivityIds: Ref> = ref([]); const formRef: Ref | null> = ref(null); +const projectActivityIds: Ref> = ref([]); const initialFormValues: Ref = ref(undefined); const showCancelMessage: Ref = ref(false); @@ -140,12 +145,19 @@ function onInvalidSubmit(e: any) { first?.scrollIntoView({ behavior: 'smooth' }); } +function onRelatedActivityInput(e: IInputEvent) { + filteredProjectActivityIds.value = projectActivityIds.value.filter((id) => + id.toUpperCase().includes(e.target.value.toUpperCase()) + ); +} + const onSubmit = async (values: any) => { try { editable.value = false; const submitData: Enquiry = omit(setEmptyStringsToNull(values) as EnquiryForm, ['user']); submitData.assignedUserId = values.user?.userId ?? undefined; + submitData.isRelated = submitData.relatedActivityId ? BasicResponse.YES : BasicResponse.NO; const result = await enquiryService.updateEnquiry(values.enquiryId, submitData); enquiryStore.setEnquiry(result.data); @@ -156,6 +168,7 @@ const onSubmit = async (values: any) => { user: values.user } }); + emit('enquiryForm:saved'); toast.success('Form saved'); } catch (e: any) { @@ -174,6 +187,7 @@ onMounted(async () => { submittedAt: new Date(props.enquiry?.submittedAt), user: assigneeOptions.value[0] ?? null }; + projectActivityIds.value = filteredProjectActivityIds.value = (await submissionService.getActivityIds()).data; }); @@ -211,11 +225,14 @@ onMounted(async () => { label="Submission date" :disabled="!editable" /> -
diff --git a/frontend/src/services/submissionService.ts b/frontend/src/services/submissionService.ts index 5966354b..78110f79 100644 --- a/frontend/src/services/submissionService.ts +++ b/frontend/src/services/submissionService.ts @@ -4,6 +4,14 @@ import { delimitEmails } from '@/utils/utils'; import type { Email } from '@/types'; export default { + /** + * @function getActivityIds + * @returns {Promise} An axios response + */ + getActivityIds() { + return appAxios().get('submission/activityIds'); + }, + /** * @function createDraft * @returns {Promise} An axios response diff --git a/frontend/src/views/housing/enquiry/EnquiryView.vue b/frontend/src/views/housing/enquiry/EnquiryView.vue index 24531d63..1fb32ded 100644 --- a/frontend/src/views/housing/enquiry/EnquiryView.vue +++ b/frontend/src/views/housing/enquiry/EnquiryView.vue @@ -42,13 +42,7 @@ onMounted(async () => { enquiryStore.setEnquiry(enquiry); enquiryStore.setNotes(notes); - if (enquiry?.relatedActivityId) { - relatedSubmission.value = ( - await submissionService.searchSubmissions({ - activityId: [enquiry.relatedActivityId] - }) - ).data[0]; - } + updateRelatedEnquiry(); } loading.value = false; @@ -63,6 +57,20 @@ const onUpdateNote = (oldNote: Note, newNote: Note) => { const onDeleteNote = (note: Note) => { enquiryStore.removeNote(note); }; + +async function updateRelatedEnquiry() { + if (getEnquiry?.value?.relatedActivityId) { + relatedSubmission.value = ( + await submissionService.searchSubmissions({ + activityId: [getEnquiry?.value?.relatedActivityId] + }) + ).data[0]; + } else relatedSubmission.value = undefined; +} + +function onEnquiryFormSaved() { + updateRelatedEnquiry(); +}