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

BC-8213 - validate room dates #3434

Merged
merged 38 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9f90a65
add max length validation for room title
odalys-dataport Oct 23, 2024
b6da67a
Merge branch 'main' of https://github.com/hpi-schul-cloud/nuxt-client…
odalys-dataport Oct 28, 2024
e40089f
add min date
odalys-dataport Oct 28, 2024
1770f85
Merge branch 'main' of https://github.com/hpi-schul-cloud/nuxt-client…
odalys-dataport Nov 1, 2024
98bbeb2
fix vuetify lang key missing warning
odalys-dataport Nov 1, 2024
27e3def
startBeforeEndDate validator
odalys-dataport Nov 3, 2024
ff8391a
adjust validator to work for both dates
odalys-dataport Nov 3, 2024
dab7e72
show prop error messages
odalys-dataport Nov 4, 2024
fa7b1a0
remove translations code
odalys-dataport Nov 7, 2024
ee8067c
fix es date format error message
odalys-dataport Nov 7, 2024
6113e73
combine error messages in date picker
odalys-dataport Nov 7, 2024
299f19f
german error message
odalys-dataport Nov 7, 2024
853c86b
translated error message
odalys-dataport Nov 7, 2024
103dd6a
solve merge conflicts in language files
odalys-dataport Nov 11, 2024
88dcc53
show notification on general error
odalys-dataport Nov 12, 2024
783fe38
only show startdate error on startdate field
odalys-dataport Nov 12, 2024
a0529e1
Merge branch 'main' of https://github.com/hpi-schul-cloud/nuxt-client…
odalys-dataport Nov 12, 2024
7b774d6
add notification on edit
odalys-dataport Nov 12, 2024
a27f8bb
Merge branch 'main' into BC-8213-validate-room-dates
odalys-dataport Nov 17, 2024
e7d1531
adjust roomform tests
odalys-dataport Nov 17, 2024
9cabbbc
add basic tests for small room components
odalys-dataport Nov 17, 2024
ccdd8c1
disable today's date for end date picker
odalys-dataport Nov 17, 2024
6d80bce
reduce validator complexity
odalys-dataport Nov 17, 2024
6d4434f
Merge branch 'main' into BC-8213-validate-room-dates
odalys-dataport Nov 18, 2024
372d29d
allow same day
odalys-dataport Nov 18, 2024
e9ed0b3
adjust BoardTile tests
odalys-dataport Nov 19, 2024
f7d27a3
BoardGrid Tests
odalys-dataport Nov 19, 2024
09c59e5
adjust RoomDetails tests
odalys-dataport Nov 19, 2024
e31eda8
handle error in component (create)
odalys-dataport Nov 19, 2024
c5f71ec
separate date compare function
odalys-dataport Nov 19, 2024
d7a5e38
test save event for correct values
odalys-dataport Nov 19, 2024
e43d8a8
handle bad requests in component
odalys-dataport Nov 22, 2024
2b99358
remove unnecessary error type
odalys-dataport Nov 24, 2024
86e730a
use flushPromises instead of nextTick
odalys-dataport Nov 24, 2024
937eaaa
add todos for complicated tests
odalys-dataport Nov 25, 2024
fabf5c5
translated error message for max length validation
odalys-dataport Nov 25, 2024
f8b521d
removed unused imports
odalys-dataport Nov 25, 2024
2cf9b0c
Merge branch 'main' into BC-8213-validate-room-dates
odalys-dataport Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/modules/data/room/RoomCreate.state.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { RoomApiFactory, RoomColor } from "@/serverApi/v3";
import { RoomCreateParams, RoomItem } from "@/types/room/Room";
import { RoomApiError, RoomCreateParams, RoomItem } from "@/types/room/Room";
import { $axios, mapAxiosErrorToResponseError } from "@/utils/api";
import { createApplicationError } from "@/utils/create-application-error.factory";
import { injectStrict, NOTIFIER_MODULE_KEY } from "@/utils/inject";
import { ref } from "vue";
import { useI18n } from "vue-i18n";

export const useRoomCreateState = () => {
const notifierModule = injectStrict(NOTIFIER_MODULE_KEY);
const { t } = useI18n();

const roomApi = RoomApiFactory(undefined, "/v3", $axios);
Expand All @@ -20,9 +18,7 @@ export const useRoomCreateState = () => {
endDate: undefined,
});

const createRoom = async (
params: RoomCreateParams
): Promise<RoomItem | undefined> => {
const createRoom = async (params: RoomCreateParams): Promise<RoomItem> => {
isLoading.value = true;
try {
odalys-dataport marked this conversation as resolved.
Show resolved Hide resolved
const room = (await roomApi.roomControllerCreateRoom(params)).data;
Expand All @@ -32,9 +28,10 @@ export const useRoomCreateState = () => {
const responseError = mapAxiosErrorToResponseError(error);

if (responseError.type === "API_VALIDATION_ERROR") {
notifierModule.show({
text: t("components.roomForm.validation.generalSaveError"),
status: "error",
throw new RoomApiError({
message: t("components.roomForm.validation.generalSaveError"),
type: responseError.type,
code: responseError.code,
});
} else {
throw createApplicationError(responseError.code);
Expand Down
1 change: 0 additions & 1 deletion src/modules/feature/room/RoomForm.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const emptyMockRoom: RoomCreateParams = {
describe("@feature-room/RoomForm", () => {
const setup = (props: ComponentProps<typeof RoomForm>) => {
const wrapper = mount(RoomForm, {
sync: false,
global: {
plugins: [createTestingVuetify(), createTestingI18n()],
},
Expand Down
6 changes: 3 additions & 3 deletions src/modules/feature/room/RoomForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ const onUpdateEndDate = (newDate: string) => {

const onSave = async () => {
const valid = await v$.value.$validate();
if (valid) {
emit("save", roomData.value);
}
// if (valid) {
emit("save", roomData.value);
// }
};

const onCancel = async () => {
Expand Down
18 changes: 15 additions & 3 deletions src/modules/page/room/RoomCreate.page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@
<script setup lang="ts">
import { Breadcrumb } from "@/components/templates/default-wireframe.types";
import DefaultWireframe from "@/components/templates/DefaultWireframe.vue";
import { RoomCreateParams } from "@/types/room/Room";
import { RoomApiError, RoomCreateParams } from "@/types/room/Room";
import { buildPageTitle } from "@/utils/pageTitle";
import { useRoomCreateState } from "@data-room";
import { RoomForm } from "@feature-room";
import { useTitle } from "@vueuse/core";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { createApplicationError } from "@/utils/create-application-error.factory";
import { injectStrict, NOTIFIER_MODULE_KEY } from "@/utils/inject";

const notifierModule = injectStrict(NOTIFIER_MODULE_KEY);
const { t } = useI18n();

const router = useRouter();
Expand All @@ -41,10 +44,19 @@ const breadcrumbs: Breadcrumb[] = [
];

const onSave = async (roomParams: RoomCreateParams) => {
const room = await createRoom(roomParams);
try {
const room = await createRoom(roomParams);

if (room) {
router.push({ name: "room-details", params: { id: room.id } });
} catch (error) {
if (error instanceof RoomApiError) {
notifierModule.show({
text: t("components.roomForm.validation.generalSaveError"),
odalys-dataport marked this conversation as resolved.
Show resolved Hide resolved
status: "error",
});
} else {
throw createApplicationError(400);
}
}
odalys-dataport marked this conversation as resolved.
Show resolved Hide resolved
};

Expand Down
19 changes: 19 additions & 0 deletions src/types/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,22 @@ export type RoomBoardItem = RoomBoardItemResponse;

export type RoomCreateParams = CreateRoomBodyParams;
export type RoomUpdateParams = UpdateRoomBodyParams;

export class RoomApiError extends Error {
readonly type: string;
readonly code: number;

constructor({
message,
type,
code,
}: {
message: string;
type: string;
code: number;
}) {
super(message);
this.type = type;
this.code = code;
}
}
Loading