Skip to content

Commit

Permalink
Merge pull request #167 from InseeFr/feat/dexie
Browse files Browse the repository at this point in the history
feat: Migrate Dexie to TypeScript
  • Loading branch information
prwozny authored Nov 22, 2024
2 parents 832cc75 + f73f696 commit 8c5afce
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 178 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pearl",
"version": "2.3.3",
"version": "2.4.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.11.1",
Expand All @@ -12,8 +12,8 @@
"@mui/styles": "^5.15.10",
"@mui/x-date-pickers": "^6.18.6",
"date-fns": "^2.30.0",
"dexie": "^3.2.1",
"dexie-react-hooks": "^1.1.1",
"dexie": "^4.0.9",
"dexie-react-hooks": "^1.1.7",
"keycloak-js": "^26.0.5",
"postcss": "8.4.31",
"react": "^18.2.0",
Expand Down
145 changes: 0 additions & 145 deletions src/types/pearl.d.ts

This file was deleted.

141 changes: 141 additions & 0 deletions src/types/pearl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
type SurveyUnitPhoneNumber = {
source: string;
favorite: boolean;
number: string;
};

type SurveyUnitPerson = {
id: number;
title: string;
firstName: string;
lastName: string;
email: string;
birthdate: number;
favoriteEmail: boolean;
privileged: boolean;
phoneNumbers: SurveyUnitPhoneNumber[];
};

type SurveyUnitAddress = {
l1: string;
l2: string;
l3: string;
l4: string;
l5: string;
l6: string;
l7: string;
elevator: boolean;
building: string;
floor: string;
door: string;
staircase: string;
cityPriorityDistrict: boolean;
};

type SurveyUnitComment = {
type: string;
value: string;
};

type SurveyUnitState = {
id: number;
date: number;
type: string;
};

type SurveyUnitSampleIdentifiers = {
bs: number;
ec: string;
le: number;
noi: number;
numfa: number;
rges: number;
ssech: number;
nolog: number;
nole: number;
autre: string;
nograp: string;
};

type SurveyUnitIdentification = {
identification: unknown;
access: unknown;
situation: unknown;
category: unknown;
occupant: unknown;
};

type SurveyUnitContactAttempt = {
status: string;
date: number;
medium: string;
};

type SurveyUnitCommunicationRequest = {
emitter: 'INTERVIEWER' | 'TOOL';
communicationTemplateId?: string;
reason?: string;
status: { date: number; status: string }[];
};

type SurveyUnitNewCommunicationRequest = {
communicationTemplateId: string;
reason: string;
creationTimestamp: number;
};

type SurveyUnitCommunicationTemplate = {
medium: string;
reason: string;
type: string;
id: string;
};

export type SurveyUnit = {
displayName: string;
id: string;
persons: SurveyUnitPerson[];
address: SurveyUnitAddress;
priority: boolean;
move: boolean;
campaign: string;
comments: SurveyUnitComment[];
sampleIdentifiers: SurveyUnitSampleIdentifiers;
states: SurveyUnitState[];
contactAttempts: SurveyUnitContactAttempt[];
contactOutcome?: { date: number; totalNumberOfContactAttempts: number; type: string };
identification: SurveyUnitIdentification;
campaignLabel: string;
managementStartDate: number;
interviewerStartDate: number;
identificationPhaseStartDate: number;
collectionStartDate: number;
collectionEndDate: number;
endDate: number;
identificationConfiguration: string;
contactOutcomeConfiguration: string;
contactAttemptConfiguration: string;
useLetterCommunication: boolean;
communicationRequests: SurveyUnitCommunicationRequest[];
communicationTemplates: SurveyUnitCommunicationTemplate[];
};

export type Notification = {
date: number;
type: string;
title: string;
messages: string[];
state: 'warning' | 'success' | 'error';
read: boolean;
detail: string;
id: number;
};

export type SyncResult = {
state: string;
messages: string[];
details: {
transmittedSurveyUnits: Record<string, string[]>;
loadedSurveyUnits: Record<string, string[]>;
};
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import Dexie from 'dexie';
import Dexie, { type EntityTable } from 'dexie';
import schema from './schema.json';
import schema2 from './schema-2.json';
import schema3 from './schema-3.json';
import schema4 from './schema-4.json';
import schema5 from './schema-5.json';
import { User } from './model/user';
import { SyncReport } from './model/syncReport';
import { SurveyUnitMissing } from './model/surveyUnitMissing';
import type { SurveyUnit, Notification } from '../../types/pearl';

export const db = new Dexie('Pearl');
export const db = new Dexie('Pearl') as Dexie & {
notification: EntityTable<Notification, 'id'>;
user: EntityTable<User, 'id'>;
syncReport: EntityTable<SyncReport, 'id'>;
surveyUnitMissing: EntityTable<SurveyUnitMissing, 'id'>;
surveyUnit: EntityTable<SurveyUnit, 'id'>;
};

export type { User, SyncReport, Notification, SurveyUnitMissing, SurveyUnit };

db.version(1).stores(schema);
// upgrade dataBase (please see https://dexie.org/docs/Tutorial/Design#database-versioning)
Expand Down
3 changes: 3 additions & 0 deletions src/utils/indexeddb/model/surveyUnitMissing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type SurveyUnitMissing = {
id: string;
};
7 changes: 7 additions & 0 deletions src/utils/indexeddb/model/syncReport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { type SyncResult } from '../../../types/pearl';

export type SyncReport = {
id: string;
transmittedSurveyUnits: SyncResult['details']['transmittedSurveyUnits'];
loadedSurveyUnits: SyncResult['details']['loadedSurveyUnits'];
};
9 changes: 9 additions & 0 deletions src/utils/indexeddb/model/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type User = {
id: string;
civility: string;
email: string;
firstName: string;
lastName: string;
phoneNumber: string;
title: string;
};
Loading

0 comments on commit 8c5afce

Please sign in to comment.