Skip to content

Commit

Permalink
feat(fa): update the quantity of an inquiry request in api & web #2213
Browse files Browse the repository at this point in the history
Approved-by: VANDERHAGHEN Luc <[email protected]>
Co-authored-by: LucVDH <[email protected]>

Closes #2213

See merge request 24-heures-insa/overbookd-mono!3156
  • Loading branch information
LeonDumestre committed Jan 2, 2025
1 parent b00761d commit 4caad9b
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 22 deletions.
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@overbookd/api",
"version": "2.22.28",
"version": "2.22.29",
"description": "API pour le logiciel de gestion du festival des 24 heures de l'INSA",
"author": "Club des 24 heures de l'INSA (https://www.24heures.org/)",
"homepage": "https://gitlab.com/24-heures-insa/overbookd-mono",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ApiProperty } from "@nestjs/swagger";
import { IsPositive } from "class-validator";
import { UpdateInquiryRequestForm } from "@overbookd/http";

export class UpdateInquiryRequestDto implements UpdateInquiryRequestForm {
@ApiProperty({ required: true })
@IsPositive()
quantity: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { InitInquiryRequestDto } from "./dto/init-inquiry.request.dto";
import { LinkInquiryDriveRequestDto } from "../../../common/dto/link-inquiry-drive.request.dto";
import { InquirySectionService } from "./inquiry-section.service";
import { FestivalEventErrorFilter } from "../../../common/festival-event-error.filter";
import { UpdateInquiryRequestDto } from "./dto/update-inquiry-request.request.dto";

@ApiBearerAuth()
@ApiTags("festival-activities")
Expand Down Expand Up @@ -235,6 +236,47 @@ export class InquirySectionController {
return this.inquiryService.addInquiryRequest(faId, inquiryRequest);
}

@UseGuards(JwtAuthGuard, PermissionsGuard)
@Permission(WRITE_FA)
@Patch(":faId/inquiry/requests/:inquirySlug")
@HttpCode(200)
@ApiResponse({
status: 200,
description: "Festival activity",
schema: {
oneOf: [
{ $ref: getSchemaPath(DraftFestivalActivityResponseDto) },
{ $ref: getSchemaPath(InReviewFestivalActivityResponseDto) },
{ $ref: getSchemaPath(ValidatedFestivalActivityResponseDto) },
{ $ref: getSchemaPath(RefusedFestivalActivityResponseDto) },
],
},
})
@ApiBody({
description:
"Inquiry request quantity to update in inquiry section of festival activity",
type: UpdateInquiryRequestDto,
})
@ApiParam({
name: "faId",
type: Number,
description: "Festival activity id",
required: true,
})
@ApiParam({
name: "inquirySlug",
type: String,
description: "Inquiry Request Slug",
required: true,
})
updateInquiryRequest(
@Param("faId", ParseIntPipe) faId: FestivalActivity["id"],
@Param("inquirySlug") slug: InquiryRequest["slug"],
@Body() inquiryRequest: UpdateInquiryRequestDto,
): Promise<FestivalActivity> {
return this.inquiryService.updateInquiryRequest(faId, slug, inquiryRequest);
}

@UseGuards(JwtAuthGuard, PermissionsGuard)
@Permission(WRITE_FA)
@Delete(":faId/inquiry/requests/:inquirySlug")
Expand Down Expand Up @@ -272,7 +314,7 @@ export class InquirySectionController {

@UseGuards(JwtAuthGuard, PermissionsGuard)
@Permission(VALIDATE_FA)
@Patch(":faId/inquiry/requests/:inquirySlug")
@Patch(":faId/inquiry/requests/:inquirySlug/link-drive")
@HttpCode(200)
@ApiResponse({
status: 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {
PrepareFestivalActivity,
TimeWindow,
} from "@overbookd/festival-event";
import { InitInquiryRequest, AddInquiryRequestForm } from "@overbookd/http";
import {
InitInquiryRequest,
AddInquiryRequestForm,
UpdateInquiryRequestForm,
} from "@overbookd/http";
import { JwtUtil } from "../../../../authentication/entities/jwt-util.entity";
import { Inquiries } from "../../common/festival-activity-common.model";
import { TeamService } from "../../../../team/team.service";
Expand Down Expand Up @@ -67,6 +71,16 @@ export class InquirySectionService {
return this.prepare.addInquiryRequest(faId, request);
}

async updateInquiryRequest(
faId: FestivalActivity["id"],
slug: InquiryRequest["slug"],
{ quantity }: UpdateInquiryRequestForm,
) {
const inquiry = await this.inquiries.find(slug);
const request = { ...inquiry, quantity };
return this.prepare.updateInquiryRequest(faId, request);
}

async removeInquiryRequest(
faId: FestivalActivity["id"],
slug: InquiryRequest["slug"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
hide-default-footer
>
<template #item.quantity="{ item }">
{{ displayQuantity(item) }}
<v-text-field
v-if="currentInquiryUpdate === item"
v-model="newQuantity"
type="number"
:rules="[isNumber, min(1)]"
density="compact"
hide-details
/>
<span v-else>{{ displayQuantity(item) }}</span>
</template>

<template #item.drive="{ item }">
Expand All @@ -30,12 +38,38 @@
</template>

<template #item.actions="{ item }">
<v-btn
icon="mdi-trash-can"
size="small"
variant="flat"
@click="removeInquiry(item)"
/>
<div v-if="currentInquiryUpdate === item">
<v-btn
icon="mdi-close"
color="error"
size="small"
density="comfortable"
rounded="pill"
@click="currentInquiryUpdate = null"
/>
<v-btn
icon="mdi-check"
color="success"
size="small"
density="comfortable"
rounded="pill"
@click="updateInquiry(item)"
/>
</div>
<div v-else>
<v-btn
icon="mdi-pencil"
size="small"
variant="flat"
@click="openInquiryUpdateForm(item)"
/>
<v-btn
icon="mdi-trash-can"
size="small"
variant="flat"
@click="removeInquiry(item)"
/>
</div>
</template>
</v-data-table>
</template>
Expand All @@ -52,6 +86,7 @@ import {
} from "@overbookd/festival-event";
import { slugifiedFilter } from "~/utils/search/search.utils";
import type { TableHeaders } from "~/utils/vuetify/component-props";
import { isNumber, min } from "~/utils/rules/input.rules";
const userStore = useUserStore();
const catalogGearStore = useCatalogGearStore();
Expand Down Expand Up @@ -143,7 +178,22 @@ const gearDrive = (inquiry: InquiryRequest): Drive | undefined => {
return "drive" in inquiry ? inquiry.drive : undefined;
};
const emit = defineEmits(["remove", "link-drive"]);
const currentInquiryUpdate = ref<InquiryRequest | null>(null);
const newQuantity = ref<number>(1);
const openInquiryUpdateForm = (inquiry: InquiryRequest) => {
currentInquiryUpdate.value = inquiry;
newQuantity.value = inquiry.quantity;
};
const emit = defineEmits(["update", "remove", "link-drive"]);
const updateInquiry = (inquiry: InquiryRequest) => {
if (currentInquiryUpdate.value?.slug !== inquiry.slug) {
currentInquiryUpdate.value = null;
return;
}
emit("update", inquiry, +newQuantity.value);
currentInquiryUpdate.value = null;
};
const removeInquiry = (inquiry: InquiryRequest) => emit("remove", inquiry);
const linkDrive = (slug: string, drive?: Drive) => {
if (!drive) return;
Expand Down
4 changes: 1 addition & 3 deletions apps/web/components/molecules/logistic/InquiryFormFields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:model-value="quantity"
type="number"
label="Quantité"
:rules="[rules.number, rules.min]"
:rules="[isNumber, min(1)]"
class="inquiry-form__quantity"
:disabled="disabled"
:hide-details="hideDetails"
Expand Down Expand Up @@ -42,8 +42,6 @@ defineProps({
},
});
const rules = { number: isNumber, min: min(1) };
const emit = defineEmits(["update:quantity"]);
const updateQuantity = (value: string) => emit("update:quantity", +value);
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
:owner="MATOS"
:hide-drive="shouldHideDrive"
@link-drive="linkDrive"
@update="updateInquiry"
@remove="removeInquiry"
/>
</div>
Expand All @@ -91,6 +92,7 @@
:owner="ELEC"
:hide-drive="shouldHideDrive"
@link-drive="linkDrive"
@update="updateInquiry"
@remove="removeInquiry"
/>
</div>
Expand All @@ -105,6 +107,7 @@
:owner="BARRIERES"
:hide-drive="shouldHideDrive"
@link-drive="linkDrive"
@update="updateInquiry"
@remove="removeInquiry"
/>
</div>
Expand Down Expand Up @@ -175,6 +178,9 @@ const addInquiry = () => {
gear.value = undefined;
quantity.value = 1;
};
const updateInquiry = (inquiry: InquiryRequest, quantity: number) => {
faStore.updateInquiryRequest(inquiry.slug, quantity);
};
const removeInquiry = (inquiry: InquiryRequest) => {
faStore.removeInquiryRequest(inquiry.slug);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
<template #item.action="{ item, index }">
<v-btn
icon="mdi-pencil"
small
fab
dark
size="small"
color="warning"
@click="startEditMode(item, index)"
/>
Expand Down Expand Up @@ -73,7 +71,6 @@
prepend-icon="mdi-check"
color="success"
size="large"
rounded
@click="saveInventory"
/>

Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@overbookd/web",
"version": "3.3.67",
"version": "3.3.68",
"description": "Application web pour le logiciel de gestion du festival des 24 heures de l'INSA",
"author": "Club des 24 heures de l'INSA (https://www.24heures.org/)",
"homepage": "https://gitlab.com/24-heures-insa/overbookd-mono",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type {
import type { IProvidePeriod } from "@overbookd/time";
import type {
AddInquiryRequestForm,
UpdateInquiryRequestForm,
PublishFeedbackForm,
ReviewApproval,
Statistics,
Expand Down Expand Up @@ -297,6 +298,17 @@ export class FestivalActivityRepository {
);
}

static updateInquiryRequest(
faId: FestivalActivity["id"],
slug: InquiryRequest["slug"],
request: UpdateInquiryRequestForm,
) {
return HttpClient.patch<FestivalActivity>(
`${this.basePath}/${faId}/inquiry/requests/${slug}`,
request,
);
}

static removeInquiryRequest(
faId: FestivalActivity["id"],
requestSlug: InquiryRequest["slug"],
Expand All @@ -321,7 +333,7 @@ export class FestivalActivityRepository {

static linkDrive(faId: FestivalActivity["id"], { slug, drive }: AssignDrive) {
return HttpClient.patch<FestivalActivity>(
`${this.basePath}/${faId}/inquiry/requests/${slug}`,
`${this.basePath}/${faId}/inquiry/requests/${slug}/link-drive`,
{ drive },
);
}
Expand Down
10 changes: 10 additions & 0 deletions apps/web/stores/festival-event/festival-activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,16 @@ export const useFestivalActivityStore = defineStore("festival-activity", {
this.selectedActivity = castActivityWithDate(res);
},

async updateInquiryRequest(slug: InquiryRequest["slug"], quantity: number) {
const res = await repo.updateInquiryRequest(
this.selectedActivity.id,
slug,
{ quantity },
);
if (isHttpError(res)) return;
this.selectedActivity = castActivityWithDate(res);
},

async removeInquiryRequest(slug: InquiryRequest["slug"]) {
const res = await repo.removeInquiryRequest(
this.selectedActivity.id,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "overbookd",
"version": "3.22.2-rc.1",
"version": "3.22.2-rc.2",
"main": "index.js",
"keywords": [],
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion utils/http/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@overbookd/http",
"version": "1.2.89",
"version": "1.2.90",
"description": "Utilitaire pour les requêtes HTTP",
"author": "Club des 24 heures de l'INSA (https: //www.24heures.org/)",
"homepage": "https://gitlab.com/24-heures-insa/overbookd-mono",
Expand Down
1 change: 1 addition & 0 deletions utils/http/src/festival-event/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Feedback, InquiryRequest } from "@overbookd/festival-event";

export type AddInquiryRequestForm = Pick<InquiryRequest, "slug" | "quantity">;
export type UpdateInquiryRequestForm = Pick<InquiryRequest, "quantity">;

export type PublishFeedbackForm = Pick<Feedback, "content">;
1 change: 1 addition & 0 deletions utils/http/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// FESTIVAL EVENT
export type {
AddInquiryRequestForm,
UpdateInquiryRequestForm,
PublishFeedbackForm,
} from "./festival-event/common.js";
export type {
Expand Down

0 comments on commit 4caad9b

Please sign in to comment.