Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle committed Nov 24, 2023
1 parent 803e2ff commit a428756
Show file tree
Hide file tree
Showing 27 changed files with 544 additions and 569 deletions.
4 changes: 2 additions & 2 deletions drama-queen/src/core/adapters/datastore/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export function createDataStore(params: {
return {
updateSurveyUnit: (surveyUnit) => db.surveyUnit.put(surveyUnit),
deleteSurveyUnit: (id) => db.surveyUnit.delete(id),
getAllSurveyUnit: () => db.surveyUnit.toArray(),
getAllSurveyUnits: () => db.surveyUnit.toArray(),
getSurveyUnit: (id) => db.surveyUnit.get(id),
getAllParadata: () => db.paradata.toArray(),
getAllParadatas: () => db.paradata.toArray(),
deleteParadata: (id) => db.paradata.delete(id),
getParadata: (id) => db.paradata.get(id),
};
Expand Down
46 changes: 23 additions & 23 deletions drama-queen/src/core/adapters/queenApi/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
nomenclatureSchema,
requiredNomenclaturesSchema,
surveyUnitSchema,
surveyUnitWithIdSchema,
} from "./parserSchema";
import {
Campaign,
Expand All @@ -32,7 +31,7 @@ export function createApiClient(params: {
const axiosInstance = axios.create({ baseURL: apiUrl, timeout: 120_000 });

const onRequest = (config: AxiosRequestConfig) => {
console.info(`[request] [${JSON.stringify(config)}]`);
//console.info(`[request] [${JSON.stringify(config)}]`);
return {
...(config as any),
headers: {
Expand Down Expand Up @@ -60,11 +59,11 @@ export function createApiClient(params: {
};

const onResponse = (response: AxiosResponse): AxiosResponse => {
console.info(`[response] [${JSON.stringify(response)}]`);
//console.info(`[response] [${JSON.stringify(response)}]`);
return response;
};

const onResponseError = (error: AxiosError): Promise<AxiosError> => {
const onResponseError = (error: AxiosError) => {
console.error(`[response error] [${JSON.stringify(error)}]`);
return Promise.reject(error);
};
Expand All @@ -87,35 +86,34 @@ export function createApiClient(params: {
axiosInstance
.get<SurveyUnit[]>(`/api/survey-units/interviewer`)
.then(({ data }) =>
data.map((surveyUnit) => surveyUnitWithIdSchema.parse(surveyUnit))
data.map((surveyUnit) => surveyUnitSchema.parse(surveyUnit))
),
{ promise: true }
),
getSurveyUnit: memoize(
(idSurveyUnit) =>
axiosInstance
.get<SurveyUnit>(`/api/survey-unit/${idSurveyUnit}`)
.then(({ data }) => ({
id: idSurveyUnit,
...surveyUnitSchema.parse(data),
})),
.get<Omit<SurveyUnit, "id">>(`/api/survey-unit/${idSurveyUnit}`)
.then(({ data }) =>
surveyUnitSchema.parse({ id: idSurveyUnit, ...data })
),
{ promise: true }
),
putSurveyUnit: (idSurveyUnit, surveyUnit) =>
axiosInstance.put<typeof surveyUnit>(
`api/survey-unit/${idSurveyUnit}`,
surveyUnit
),
axiosInstance
.put<typeof surveyUnit>(`api/survey-unit/${idSurveyUnit}`, surveyUnit)
.then(() => undefined),
putSurveyUnitsData: (surveyUnitsData) =>
axiosInstance.put<typeof surveyUnitsData>(
`/api/survey-units/data`,
surveyUnitsData
),
axiosInstance
.put<typeof surveyUnitsData>(`/api/survey-units/data`, surveyUnitsData)
.then(() => undefined),
postSurveyUnitInTemp: (idSurveyUnit, surveyUnit) =>
axiosInstance.post<typeof surveyUnit>(
`api/survey-unit/${idSurveyUnit}/temp-zone`,
surveyUnit
),
axiosInstance
.post<typeof surveyUnit>(
`api/survey-unit/${idSurveyUnit}/temp-zone`,
surveyUnit
)
.then(() => undefined),
getCampaigns: memoize(
() =>
axiosInstance
Expand Down Expand Up @@ -147,6 +145,8 @@ export function createApiClient(params: {
{ promise: true }
),
postParadata: (paradata) =>
axiosInstance.post<typeof paradata>(`/api/paradata`, paradata),
axiosInstance
.post<typeof paradata>(`/api/paradata`, paradata)
.then(() => undefined),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ const stateDataSchema = z.object({
});

export const surveyUnitSchema = z.object({
id: z.string(),
questionnaireId: z.string(),
personalization: z.union([z.object({}).array(), z.object({})]),
data: surveyUnitDataSchema,
comment: z.object({}), // not implemented yet, only present in test data
stateData: stateDataSchema.optional(),
});

export const surveyUnitWithIdSchema = surveyUnitSchema.extend({
id: z.string(),
});
});
4 changes: 2 additions & 2 deletions drama-queen/src/core/ports/DataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Paradata, SurveyUnit } from "core/model";
export type DataStore = {
updateSurveyUnit: (surveyUnit: SurveyUnit) => Promise<string>;
deleteSurveyUnit: (id: string) => Promise<void>;
getAllSurveyUnit: () => Promise<SurveyUnit[] | undefined>;
getAllSurveyUnits: () => Promise<SurveyUnit[] | undefined>;
getSurveyUnit: (id: string) => Promise<SurveyUnit | undefined>;
getAllParadata: () => Promise<Paradata[] | undefined>;
getAllParadatas: () => Promise<Paradata[] | undefined>;
deleteParadata: (id: string) => Promise<void>;
getParadata: (id: string) => Promise<Paradata | undefined>;
};
Empty file.
21 changes: 16 additions & 5 deletions drama-queen/src/core/ports/QueenApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Campaign, IdAndQuestionnaireId, Nomenclature, Paradata, Questionnaire, RequiredNomenclatures, SurveyUnit } from "core/model";
import {
Campaign,
IdAndQuestionnaireId,
Nomenclature,
Paradata,
Questionnaire,
RequiredNomenclatures,
SurveyUnit,
} from "core/model";

export type QueenApi = {
getSurveyUnitsIdsAndQuestionnaireIdsByCampaign: (
Expand All @@ -12,7 +20,10 @@ export type QueenApi = {
*/
getSurveyUnits: () => Promise<SurveyUnit[]>;
getSurveyUnit: (idSurveyUnit: string) => Promise<SurveyUnit>;
putSurveyUnit: (idSurveyUnit: string, surveyUnit: SurveyUnit) => void;
putSurveyUnit: (
idSurveyUnit: string,
surveyUnit: SurveyUnit
) => Promise<void>;
/**
* Endpoint in development
* @param
Expand All @@ -21,16 +32,16 @@ export type QueenApi = {
*/
putSurveyUnitsData: (
surveyUnitsData: Omit<SurveyUnit, "questionnaireId">[]
) => void;
) => Promise<void>;
postSurveyUnitInTemp: (
idSurveyUnit: string,
surveyUnit: SurveyUnit
) => void;
) => Promise<void>;
getCampaigns: () => Promise<Campaign[]>;
getQuestionnaire: (idQuestionnaire: string) => Promise<Questionnaire>;
getRequiredNomenclaturesByCampaign: (
idCampaign: string
) => Promise<RequiredNomenclatures>;
getNomenclature: (idNomenclature: string) => Promise<Nomenclature>;
postParadata: (paradata: Paradata) => void;
postParadata: (paradata: Paradata) => Promise<void>;
};
21 changes: 21 additions & 0 deletions drama-queen/src/core/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,32 @@ export async function createCore(params: CoreParams) {
});
})();

const dataStore = await (async () => {
const { createDataStore } = await import("core/adapters/datastore/default");
/**
* TODO : replace schema (There are impact on legacy queens)
schema: {
paradata: "idSU",
surveyUnit: "id",
}
version: 3,
*/
return createDataStore({
name: "Queen",
schema: {
paradata: "++id,idSU,events",
surveyUnit: "id,data,stateData,personalization,comment,questionnaireId",
},
version: 2,
});
})();

const core = createCoreFromUsecases({
thunksExtraArgument: {
coreParams: params,
oidc,
queenApi,
dataStore,
},
usecases,
});
Expand Down
23 changes: 0 additions & 23 deletions drama-queen/src/core/usecases/downloadData/evt.ts

This file was deleted.

40 changes: 0 additions & 40 deletions drama-queen/src/core/usecases/downloadData/selectors.ts

This file was deleted.

86 changes: 0 additions & 86 deletions drama-queen/src/core/usecases/downloadData/state.ts

This file was deleted.

Loading

0 comments on commit a428756

Please sign in to comment.