Skip to content

Commit

Permalink
Fix UI/UX consistency, adjusted db model and backend logic, clean up …
Browse files Browse the repository at this point in the history
…formatting
  • Loading branch information
wilwong89 committed Feb 15, 2024
1 parent 17f1fca commit 4ccea8d
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 65 deletions.
13 changes: 10 additions & 3 deletions app/src/controllers/note.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { noteService } from '../services';
import { NIL } from 'uuid';

import { noteService, userService } from '../services';
import { getCurrentIdentity } from '../components/utils';

import type { NextFunction, Request, Response } from '../interfaces/IExpress';
import { CurrentUser } from '../types';

const controller = {
createNote: async (req: Request, res: Response, next: NextFunction) => {
try {
const response = await noteService.createNote(req.body, req.currentUser as CurrentUser);
const userId = await userService.getCurrentUserId(getCurrentIdentity(req.currentUser, NIL), NIL);

// TODO: define body type in request
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const body = req.body as any;
const response = await noteService.createNote({ ...body, createdBy: userId });
res.status(200).send(response);
} catch (e: unknown) {
next(e);
Expand Down
4 changes: 1 addition & 3 deletions app/src/db/migrations/20231212000000_init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ export async function up(knex: Knex): Promise<void> {
table.text('note').defaultTo('').notNullable();
table.text('note_type').defaultTo('').notNullable();
table.text('title').defaultTo('').notNullable();
table.text('createdAt');
table.text('createdBy');
table.unique(['note_id']);
stamps(knex, table);
})
)

Expand Down
12 changes: 8 additions & 4 deletions app/src/db/models/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export default {
note_type: input.noteType,
submission: { connect: { submissionId: input.submissionId } },
title: input.title,
createdAt: input.createdAt ?? new Date().toISOString(),
createdBy: input.createdBy
createdAt: input.createdAt ? new Date(input.createdAt) : null,
createdBy: input.createdBy as string,
updatedAt: input.updatedAt ? new Date(input.updatedAt) : null,
updatedBy: input.updatedBy as string
};
},

Expand All @@ -45,8 +47,10 @@ export default {
submission: submission.fromPrismaModel(input.submission) as ChefsSubmissionForm,
submissionId: input.submission_id as string,
title: input.title || '',
createdAt: input.createdAt,
createdBy: input.createdBy
createdAt: input.createdAt?.toISOString() ?? null,
createdBy: input.createdBy,
updatedAt: input.updatedAt?.toISOString() ?? null,
updatedBy: input.updatedBy
};
}
};
8 changes: 5 additions & 3 deletions app/src/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ model identity_provider {
}

model note {
note_id String @id @unique(map: "note_note_id_unique") @db.Uuid
note_id String @id @db.Uuid
submission_id String @db.Uuid
note String @default("")
note_type String @default("")
title String @default("")
createdAt String?
createdBy String?
createdBy String? @default("00000000-0000-0000-0000-000000000000")
createdAt DateTime? @default(now()) @db.Timestamptz(6)
updatedBy String?
updatedAt DateTime? @db.Timestamptz(6)
submission submission @relation(fields: [submission_id], references: [submissionId], onDelete: Cascade, map: "note_submission_id_foreign")
}

Expand Down
15 changes: 8 additions & 7 deletions app/src/services/note.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import prisma from '../db/dataConnection';
import { note } from '../db/models';
import { v4 as uuidv4 } from 'uuid';
import { addDashesToUuid } from '../components/utils';

import type { CurrentUser, Note } from '../types';
import { JwtPayload } from 'jsonwebtoken';
import type { Note } from '../types';

const service = {
/**
* @function createNote
* Creates a Permit
* @param note Note Object
* Creates a note
* @param data Note Object
* @param identityId string
* @returns {Promise<object>} The result of running the findUnique operation
*/
createNote: async (data: Note, currentUser: CurrentUser) => {
createNote: async (data: Note) => {
const newNote = {
...data,
createdBy: addDashesToUuid((currentUser.tokenPayload as JwtPayload)?.idir_user_guid),
noteId: uuidv4()
};
const create = await prisma.note.create({
Expand Down Expand Up @@ -44,6 +42,9 @@ const service = {
include: { user: true }
}
},
orderBy: {
createdAt: 'desc'
},
where: {
submission_id: submissionId
}
Expand Down
5 changes: 2 additions & 3 deletions app/src/types/Note.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IStamps } from '../interfaces/IStamps';
import type { ChefsSubmissionForm } from './ChefsSubmissionForm';

export type Note = {
Expand All @@ -7,6 +8,4 @@ export type Note = {
noteType: string;
submission: ChefsSubmissionForm;
title: string;
createdAt: string | null;
createdBy: string | null;
};
} & Partial<IStamps>;
28 changes: 15 additions & 13 deletions frontend/src/components/note/NoteCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { onMounted, ref } from 'vue';
import { Card, Divider } from '@/lib/primevue';
import { userService } from '@/services';
import { formatDate } from '@/utils/formatters';
import { formatDateShort } from '@/utils/formatters';
import type { Ref } from 'vue';
import type { Note } from '@/types';
Expand All @@ -17,21 +17,21 @@ type Props = {
const props = withDefaults(defineProps<Props>(), {});
// State
const cardData: Ref<Note> = ref(props.note);
const userName: Ref<string> = ref('');
onMounted(async () => {
onMounted(() => {
if (props.note.createdBy) {
const res = (await userService.searchUsers({ identityId: [props.note.createdBy] })).data;
userName.value = res.length ? res.pop().fullName : '';
userService.searchUsers({ userId: [props.note.createdBy] }).then((res) => {
userName.value = res?.data.length ? res?.data[0].fullName : '';
});
}
});
</script>

<template>
<Card>
<template #title>
<h3 class="mt-3 mb-1">{{ cardData.title }}</h3>
<h3 class="mt-1 mb-1">{{ props.note.title }}</h3>
<Divider type="solid" />
</template>
<template #content>
Expand All @@ -41,7 +41,7 @@ onMounted(async () => {
<div class="grid">
<p class="col-12">
<span class="key font-bold">Date:</span>
{{ cardData.createdAt ? formatDate(cardData.createdAt ?? '') : undefined }}
{{ props.note.createdAt ? formatDateShort(props.note.createdAt ?? '') : undefined }}
</p>
</div>
</div>
Expand All @@ -58,20 +58,18 @@ onMounted(async () => {
<div class="col-12 md:col-6 lg:col-4">
<div class="grid">
<p class="col-12">
<span class="key font-bold">Category:</span>
{{ cardData.noteType }}
<span class="key font-bold">Note type:</span>
{{ props.note.noteType }}
</p>
</div>
</div>
<div class="col-12 mb-2">
{{ cardData.note }}
</div>
<p class="col-12 mt-0 mb-0 note-content">{{ props.note.note }}</p>
</div>
</template>
</Card>
</template>

<style lang="scss">
<style scoped lang="scss">
h2 {
margin: 0;
}
Expand All @@ -98,4 +96,8 @@ p {
}
}
}
.note-content {
white-space: pre;
text-wrap: balance;
}
</style>
42 changes: 24 additions & 18 deletions frontend/src/components/note/NoteModal.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<script setup lang="ts">
import { Form } from 'vee-validate';
// import { ref } from 'vue';
import { object, string } from 'yup';
import { Dropdown, InputText, TextArea } from '@/components/form';
import { Button, Dialog } from '@/lib/primevue';
// import { noteService } from '@/services';
import { NoteTypes } from '@/utils/constants';
import { NOTE_TYPES } from '@/utils/enums';
import { onMounted } from 'vue';
import { formatDateShort } from '@/utils/formatters';
// import type { Ref } from 'vue';
import type { Note } from '@/types';
Expand All @@ -30,6 +28,7 @@ const visible = defineModel<boolean>('visible');
// Default form values
let initialFormValues: any = {
createdAt: formatDateShort(new Date().toISOString()),
note: props.note?.note,
noteType: NOTE_TYPES.GENERAL
};
Expand All @@ -47,12 +46,9 @@ const formSchema = object({
function onSubmit(data: any, { resetForm }) {
if (props.note) initialFormValues = data;
else resetForm();
emit('note:submit', data);
}
onMounted(async () => {
// permitTypes.value = (await permitService.getPermitTypes())?.data;
});
</script>

<template>
Expand All @@ -65,6 +61,11 @@ onMounted(async () => {
>
<!-- eslint-enable vue/no-v-model-argument -->
<template #header>
<font-awesome-icon
icon="fa-solid fa-plus"
fixed-width
class="mr-2"
/>
<span class="p-dialog-title">Add note</span>
</template>

Expand All @@ -74,26 +75,31 @@ onMounted(async () => {
@submit="onSubmit"
>
<div class="formgrid grid">
<div class="field col">
<label class="font-bold">Date</label>
<p>{{ new Date() }}</p>
</div>
<InputText
class="col-12"
class="col-6"
name="createdAt"
label="Date"
:disabled="true"
/>
<div class="col-6" />
<Dropdown
class="col-6"
name="noteType"
label="Note type"
:options="NoteTypes"
/>
<div class="col-6" />
<InputText
class="col-6"
name="title"
label="Title"
/>
<div class="col-6" />
<TextArea
class="col-12"
name="note"
label="Note"
/>
<Dropdown
class="col-12 lg:col-6"
name="noteType"
label="Note type"
:options="NoteTypes"
/>
<div class="field col-12 flex">
<div class="flex-auto">
<Button
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/permit/PermitCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async function onPermitSubmit(data: Permit) {
/>
</template>

<style lang="scss">
<style scoped lang="scss">
h2 {
margin: 0;
}
Expand Down
6 changes: 0 additions & 6 deletions frontend/src/types/Note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,4 @@ export type Note = {
noteType: string;
submissionId: string;
title: string;

// note_id: string; // Primary Key
// note: string;
// note_type: string;
// submission_id: string;
// title: string;
} & Partial<IStamps>;
8 changes: 4 additions & 4 deletions frontend/src/views/SubmissionView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { RouteNames } from '@/utils/constants';
import { chefsService, documentService, noteService, permitService } from '@/services';
import type { Ref } from 'vue';
import type { Document, Permit, Note, User } from '@/types';
import type { Document, Permit, Note } from '@/types';
// Props
type Props = {
Expand Down Expand Up @@ -43,7 +43,7 @@ async function onNoteSubmit(data: any) {
try {
const result = (await noteService.createNote({ ...data, submissionId: props.submissionId })).data;
toast.success('Note saved');
notes.value.push(result);
notes.value.unshift(result);
} catch {
toast.error('Note save error');
}
Expand Down Expand Up @@ -183,7 +183,7 @@ onMounted(async () => {
<TabPanel header="Notes">
<div class="flex flex-row pb-2">
<div class="flex flex-grow-1 align-items-end">
<p class="font-bold">Notes:</p>
<p class="font-bold">Notes ({{ notes.length }})</p>
</div>
<div class="flex flex-none">
<Button
Expand Down Expand Up @@ -215,7 +215,7 @@ onMounted(async () => {
</TabView>
</template>

<style lang="scss">
<style scoped lang="scss">
.p-tabview {
.p-tabview-title {
font-size: 1.1rem;
Expand Down

0 comments on commit 4ccea8d

Please sign in to comment.