Skip to content

Commit

Permalink
Re-jigging some DTO definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
buchananwill committed Apr 4, 2024
1 parent abaf4bc commit a3c8b65
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 53 deletions.
29 changes: 12 additions & 17 deletions app/api/actions/curriculum-delivery-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ActionResponsePromise } from './actionResponse';
import { WorkProjectSeriesSchemaDto } from '../dtos/WorkProjectSeriesSchemaDtoSchema';
import { API_BASE_URL, Page } from '../main';
import { GraphDto, GraphDtoPutRequestBody } from '../zod-mods';
import { WorkSeriesBundleDeliveryDto } from '../dtos/WorkSeriesBundleDeliveryDtoSchema';
import { WorkSeriesBundleAssignmentDto } from '../dtos/WorkSeriesBundleAssignmentDtoSchema';
import { WorkSeriesSchemaBundleLeanDto } from '../dtos/WorkSeriesSchemaBundleLeanDtoSchema';
import { OrganizationDto } from '../dtos/OrganizationDtoSchema';
import {
Expand All @@ -16,6 +16,7 @@ import {
putRequestWithDifferentReturnType
} from './template-actions';
import { OrganizationTypeDto } from '../dtos/OrganizationTypeDtoSchema';
import { LongLongTuple } from '../dtos/LongLongTupleSchema';

const SCHEMA_URL = `${API_BASE_URL}/workProjectSeriesSchemas`;

Expand All @@ -38,11 +39,11 @@ export async function deleteCurriculumDeliveryModels(schemaIdList: string[]) {
}
export async function getBundleDeliveriesByOrgType(
orgType: string
): ActionResponsePromise<WorkSeriesBundleDeliveryDto[]> {
): ActionResponsePromise<WorkSeriesBundleAssignmentDto[]> {
let url = SCHEMA_URL;
url = `${url}/deliveries/organizationType/${orgType.replaceAll(' ', '%20')}`;
url = `${url}/assignments/organizationType/${orgType.replaceAll(' ', '%20')}`;

return await getWithoutBody<WorkSeriesBundleDeliveryDto[]>(url);
return await getWithoutBody<WorkSeriesBundleAssignmentDto[]>(url);
}

export async function getSchemasByIdList(idList: string[]) {
Expand Down Expand Up @@ -84,8 +85,8 @@ export async function putOrganizationGraph(
}
export async function getCurriculumDeliveries(
idList: number[]
): ActionResponsePromise<WorkSeriesBundleDeliveryDto[]> {
const urlForDeliveries = `${SCHEMA_URL}/deliveries/by-party-id`;
): ActionResponsePromise<WorkSeriesBundleAssignmentDto[]> {
const urlForDeliveries = `${SCHEMA_URL}/assignments/by-party-id`;
return getDtoListByIds(idList, urlForDeliveries);
}

Expand Down Expand Up @@ -124,18 +125,12 @@ export async function postModels(
): ActionResponsePromise<WorkProjectSeriesSchemaDto[]> {
return postEntities(modelList, SCHEMA_URL);
}

export interface CreateBundleAssignmentDto {
partyId: number;
bundleId: number;
}

export async function postBundleDeliveries(
bundleAssignments: CreateBundleAssignmentDto[]
): ActionResponsePromise<WorkSeriesBundleDeliveryDto[]> {
const bundlePostUrl = `${SCHEMA_URL}/deliveries`;
bundleAssignments: LongLongTuple[]
): ActionResponsePromise<WorkSeriesBundleAssignmentDto[]> {
const bundlePostUrl = `${SCHEMA_URL}/assignments`;
return postEntitiesWithDifferentReturnType<
CreateBundleAssignmentDto[],
WorkSeriesBundleDeliveryDto[]
LongLongTuple[],
WorkSeriesBundleAssignmentDto[]
>(bundleAssignments, bundlePostUrl);
}
6 changes: 6 additions & 0 deletions app/api/dtos/LongLongTupleSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { z } from 'zod';
export const LongLongTupleSchema = z.object({
longOne: z.number(),
longTwo: z.number()
});
export type LongLongTuple = z.infer<typeof LongLongTupleSchema>;
6 changes: 0 additions & 6 deletions app/api/dtos/PartyIdBundleIdTupleSchema.ts

This file was deleted.

7 changes: 7 additions & 0 deletions app/api/dtos/ScheduleCellDTOSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { z } from 'zod';
export const ScheduleCellDTOSchema = z.object({
principalValue: z.string(),
leftBottom: z.string(),
rightBottom: z.string()
});
export type ScheduleCellDTO = z.infer<typeof ScheduleCellDTOSchema>;
7 changes: 0 additions & 7 deletions app/api/dtos/ScheduleCellSchema.ts

This file was deleted.

10 changes: 10 additions & 0 deletions app/api/dtos/WorkSeriesBundleAssignmentDtoSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { WorkSeriesSchemaBundleLeanDtoSchema } from './WorkSeriesSchemaBundleLeanDtoSchema';
import { z } from 'zod';
export const WorkSeriesBundleAssignmentDtoSchema = z.object({
id: z.number(),
partyId: z.number(),
workSeriesSchemaBundle: WorkSeriesSchemaBundleLeanDtoSchema
});
export type WorkSeriesBundleAssignmentDto = z.infer<
typeof WorkSeriesBundleAssignmentDtoSchema
>;
8 changes: 0 additions & 8 deletions app/api/dtos/WorkSeriesBundleDeliveryDtoSchema.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ConfirmActionModal,
useModal
} from '../../../generic/components/modals/confirm-action-modal';
import { LongLongTuple } from '../../../api/dtos/LongLongTupleSchema';

export function parseStringStringToIntInt(
entry: [string, string]
Expand Down Expand Up @@ -56,12 +57,12 @@ export function BundleAssignmentsProvider({

const handleConfirm = () => {
const curriedMapper = (numberTuple: [number, number]) => {
return applyStringKeysToIntValues(['partyId', 'bundleId'], numberTuple);
return applyStringKeysToIntValues(['longOne', 'longTwo'], numberTuple);
};
const mappedBundles = Object.entries(bundleAssignmentState)
.map(parseStringStringToIntInt)
.map(curriedMapper);
const apiPayload = mappedBundles as { partyId: number; bundleId: number }[];
const apiPayload = mappedBundles as LongLongTuple[];

postBundleDeliveries(apiPayload).then((r) => {
if (r.status < 300 && r.data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { WorkSeriesBundleDeliveryDto } from '../../../api/dtos/WorkSeriesBundleDeliveryDtoSchema';
import { WorkSeriesBundleAssignmentDto } from '../../../api/dtos/WorkSeriesBundleAssignmentDtoSchema';
import {
StringMap,
StringMapPayload
} from '../../../contexts/string-map-context/string-map-reducer';

export function mapToPartyIdBundleIdRecords(
bundles: WorkSeriesBundleDeliveryDto[]
bundles: WorkSeriesBundleAssignmentDto[]
) {
const bundleAssignments = {} as StringMap<string>;
const initialPayload = [] as StringMapPayload<string>[];
bundles.forEach((bundleDeliveryDto) => {
const partyIdString = bundleDeliveryDto.partyId.toString();
bundles.forEach((bundleAssignment) => {
const partyIdString = bundleAssignment.partyId.toString();
const bundleIdString =
bundleDeliveryDto.workSeriesSchemaBundle.id.toString();
bundleAssignment.workSeriesSchemaBundle.id.toString();
bundleAssignments[partyIdString] = bundleIdString;
initialPayload.push({ key: partyIdString, data: bundleIdString });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { WorkProjectSeriesSchemaDto } from '../../api/dtos/WorkProjectSeriesSche
import React, { ReactElement } from 'react';
import { DataNode } from '../../api/zod-mods';
import { PartyDto } from '../../api/dtos/PartyDtoSchema';
import { WorkSeriesBundleDeliveryDto } from '../../api/dtos/WorkSeriesBundleDeliveryDtoSchema';
import { WorkSeriesBundleAssignmentDto } from '../../api/dtos/WorkSeriesBundleAssignmentDtoSchema';
import { useCurriculumModelContext } from '../../curriculum/delivery-models/contexts/use-curriculum-model-context';
import { NodeComponent } from '../nodes/node-component';

export function useWorkSeriesBundleNodeElements(
nodes: DataNode<PartyDto>[],
bundles: WorkSeriesBundleDeliveryDto[]
bundles: WorkSeriesBundleAssignmentDto[]
) {
const { curriculumModelsMap } = useCurriculumModelContext();
return nodes.map((d, index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, { PropsWithChildren, useEffect, useMemo } from 'react';
import { Card } from '@nextui-org/card';
import CurriculumDeliveryDetails from './curriculum-delivery-details';
import { NodePayload } from '../../force-graph-page';
import { WorkSeriesBundleDeliveryDto } from '../../../api/dtos/WorkSeriesBundleDeliveryDtoSchema';
import { WorkSeriesBundleAssignmentDto } from '../../../api/dtos/WorkSeriesBundleAssignmentDtoSchema';
import { useBundleAssignmentsContext } from '../../../curriculum/delivery-models/contexts/use-bundle-assignments-context';
import { OrganizationDto } from '../../../api/dtos/OrganizationDtoSchema';
import { HasNumberIdDto } from '../../../api/dtos/HasNumberIdDtoSchema';
Expand Down Expand Up @@ -64,7 +64,7 @@ export const CurriculumDeliveryGraphPageKey = 'curriculum-delivery-graph-page';

export default function CurriculumDeliveryGraph({
bundles
}: PropsWithChildren & { bundles: WorkSeriesBundleDeliveryDto[] }) {
}: PropsWithChildren & { bundles: WorkSeriesBundleAssignmentDto[] }) {
const { nodes, nodesRef, linksRef } = useNodeAndLinkRefs<OrganizationDto>();

const { dispatch } = useBundleAssignmentsContext();
Expand Down
4 changes: 2 additions & 2 deletions app/graphing/nodes/node-component-sky-hook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NodeComponentContext } from './node-component-context';
import React, { PropsWithChildren } from 'react';
import { PartyDto } from '../../api/dtos/PartyDtoSchema';
import { DataNode } from '../../api/zod-mods';
import { WorkSeriesBundleDeliveryDto } from '../../api/dtos/WorkSeriesBundleDeliveryDtoSchema';
import { WorkSeriesBundleAssignmentDto } from '../../api/dtos/WorkSeriesBundleAssignmentDtoSchema';

import { useWorkSeriesBundleNodeElements } from '../aggregate-functions/use-work-series-bundle-node-elements';

Expand All @@ -14,7 +14,7 @@ export default function NodeComponentSkyHook({
bundles
}: {
nodes: DataNode<PartyDto>[];
bundles: WorkSeriesBundleDeliveryDto[];
bundles: WorkSeriesBundleAssignmentDto[];
} & PropsWithChildren) {
const workSeriesBundleNodeElements = useWorkSeriesBundleNodeElements(
nodes,
Expand Down
4 changes: 2 additions & 2 deletions app/timetables/timetable-period.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { ScheduleCell } from '../api/dtos/ScheduleCellSchema';
import { ScheduleCellDTO } from '../api/dtos/ScheduleCellDTOSchema';

interface TimetablePeriodProps {
periodInfo: ScheduleCell;
periodInfo: ScheduleCellDTO;
}

function TimetablePeriod({ periodInfo }: TimetablePeriodProps) {
Expand Down

0 comments on commit a3c8b65

Please sign in to comment.