Skip to content

Commit

Permalink
migration: postgres mes-adresses-api (#945)
Browse files Browse the repository at this point in the history
* update api-bal open-api

* update front

* change open id class

* insert/update positions

* correct create/update numero/toponyme

* correct build

* correct wording

* correct batch numero -> toponyme null

* refacto openapi

* test ci

* test ci

* test ci

* test ci

* correct souncloud alert

* delete package mongoose
  • Loading branch information
fufeck authored Sep 10, 2024
1 parent f332be0 commit 3c7b339
Show file tree
Hide file tree
Showing 89 changed files with 509 additions and 648 deletions.
2 changes: 1 addition & 1 deletion components/bal/address-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function AddressEditor({ commune, closeForm }: AddressEditorProps) {
<ToponymeEditor commune={commune} closeForm={closeForm} />
) : (
<NumeroEditor
initialVoieId={voie?._id}
initialVoieId={voie?.id}
commune={commune}
hasPreview
closeForm={closeForm}
Expand Down
2 changes: 1 addition & 1 deletion components/bal/commune-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function CommuneTab({ commune, openRecoveryDialog }: CommuneTabProps) {
<Pane overflowY="auto">
{!token && <ReadOnlyInfos openRecoveryDialog={openRecoveryDialog} />}
{signalements.length > 0 && (
<SignalementsInfos balId={baseLocale._id} signalements={signalements} />
<SignalementsInfos balId={baseLocale.id} signalements={signalements} />
)}
{token && baseLocale.status !== BaseLocale.status.DEMO && (
<HabilitationInfos commune={commune} />
Expand Down
41 changes: 19 additions & 22 deletions components/bal/numero-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ import DisabledFormInput from "@/components/disabled-form-input";
import {
BasesLocalesService,
Numero,
NumeroPopulate,
NumerosService,
Voie,
VoiesService,
} from "@/lib/openapi";
import { CommuneType } from "@/types/commune";
Expand All @@ -40,7 +38,7 @@ const REMOVE_TOPONYME_LABEL = "Aucun toponyme";

interface NumeroEditorProps {
initialVoieId?: string;
initialValue?: Numero | NumeroPopulate;
initialValue?: Numero;
commune: CommuneType;
hasPreview?: boolean;
closeForm: () => void;
Expand All @@ -61,11 +59,9 @@ function NumeroEditor({
certificationBtnProps,
onVoieChanged,
}: NumeroEditorProps) {
const [voieId, setVoieId] = useState(
initialVoieId || (initialValue?.voie as unknown as Voie)?._id
);
const [voieId, setVoieId] = useState(initialVoieId || initialValue?.voieId);
const [selectedNomToponyme, setSelectedNomToponyme] = useState("");
const [toponymeId, setToponymeId] = useState(initialValue?.toponyme);
const [toponymeId, setToponymeId] = useState(initialValue?.toponymeId);
const [isLoading, setIsLoading] = useState(false);
const [certifie, setCertifie] = useState(initialValue?.certifie || false);
const [numero, onNumeroChange] = useInput(
Expand Down Expand Up @@ -99,7 +95,7 @@ function NumeroEditor({
const getEditedVoie = useCallback(async () => {
if (nomVoie) {
try {
const newVoie = await BasesLocalesService.createVoie(baseLocale._id, {
const newVoie = await BasesLocalesService.createVoie(baseLocale.id, {
nom: nomVoie,
});
return newVoie;
Expand All @@ -111,12 +107,12 @@ function NumeroEditor({
}
}

return { _id: voieId };
}, [baseLocale._id, nomVoie, voieId, setValidationMessages]);
return { id: voieId };
}, [baseLocale.id, nomVoie, voieId, setValidationMessages]);

const getNumeroBody = useCallback(() => {
const body = {
toponyme: toponymeId,
toponymeId,
numero: Number(numero),
suffixe: suffixe?.length > 0 ? suffixe.toLowerCase().trim() : null,
comment: comment.length > 0 ? comment : null,
Expand All @@ -128,6 +124,7 @@ function NumeroEditor({
const positions = [];
markers.forEach((marker) => {
positions.push({
id: marker.id,
point: {
type: "Point",
coordinates: [marker.longitude, marker.latitude],
Expand Down Expand Up @@ -159,11 +156,11 @@ function NumeroEditor({

const voie = await getEditedVoie();

if (initialValue?._id) {
if (initialValue?.id) {
const updateNumero = toaster(
() =>
NumerosService.updateNumero(initialValue._id, {
voie: voie._id,
NumerosService.updateNumero(initialValue.id, {
voieId: voie.id,
...body,
}),
"Le numéro a bien été modifié",
Expand All @@ -175,7 +172,7 @@ function NumeroEditor({
await updateNumero();
} else {
const createNumero = toaster(
() => VoiesService.createNumero(voie._id, body),
() => VoiesService.createNumero(voie.id, body),
"Le numéro a bien été ajouté",
"Le numéro n’a pas pu être ajouté",
(err) => {
Expand All @@ -192,7 +189,7 @@ function NumeroEditor({
await reloadParcelles();
}

if (initialVoieId !== voie._id) {
if (initialVoieId !== voie.id) {
reloadVoies();
}

Expand Down Expand Up @@ -277,7 +274,7 @@ function NumeroEditor({
useEffect(() => {
let nom = null;
if (voieId) {
nom = voies.find((voie) => voie._id === voieId).nom;
nom = voies.find((voie) => voie.id === voieId).nom;
}

setSelectedNomVoie(nom);
Expand All @@ -286,15 +283,15 @@ function NumeroEditor({
useEffect(() => {
let nom = null;
if (toponymeId) {
nom = toponymes.find((toponyme) => toponyme._id === toponymeId).nom;
nom = toponymes.find((toponyme) => toponyme.id === toponymeId).nom;
}

setSelectedNomToponyme(nom);
}, [toponymeId, toponymes]);

return (
<Form
editingId={initialValue?._id}
editingId={initialValue?.id}
closeForm={closeForm}
onFormSubmit={onFormSubmit}
>
Expand Down Expand Up @@ -338,13 +335,13 @@ function NumeroEditor({
}}
>
<option value={null}>
{initialValue?.toponyme
{initialValue?.toponymeId
? REMOVE_TOPONYME_LABEL
: "- Choisir un toponyme -"}
</option>
{sortBy(toponymes, (t) => normalizeSort(t.nom)).map(
({ _id, nom }) => (
<option key={_id} value={_id}>
({ id, nom }) => (
<option key={id} value={id}>
{nom}
</option>
)
Expand Down
4 changes: 2 additions & 2 deletions components/bal/numero-editor/numero-voie-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ function NumeroVoieSelector({
onChange={handleVoieChange}
>
{!voieId && <option value="">- Choisir une voie-</option>}
{sortBy(voies, (v) => normalizeSort(v.nom)).map(({ _id, nom }) => (
<option key={_id} value={_id}>
{sortBy(voies, (v) => normalizeSort(v.nom)).map(({ id, nom }) => (
<option key={id} value={id}>
{nom}
</option>
))}
Expand Down
4 changes: 2 additions & 2 deletions components/bal/position-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ function PositionEditor({
useEffect(() => {
if (initialPositions) {
const positions = initialPositions.map((position) => ({
id: position.id,
longitude: position.point.coordinates[0],
latitude: position.point.coordinates[1],
type: position.type,
}));

positions.forEach((position) => addMarker(position));
} else {
handleAddMarker();
Expand Down Expand Up @@ -90,7 +90,7 @@ function PositionEditor({
.filter(({ isDisabled }) => !isDisabled)
.map((marker) => (
<PositionItem
key={marker._id}
key={marker.id}
marker={marker}
isRemovable={isToponyme ? false : markers.length === 1}
handleChange={updateMarker}
Expand Down
6 changes: 3 additions & 3 deletions components/bal/position-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ function PositionItem({
const onSelect = useCallback(
(e) => {
const type = e.target.value;
handleChange && handleChange(marker._id, { ...marker, type });
handleChange && handleChange(marker.id, { ...marker, type });
},
[marker, handleChange]
);

const removeMarker = useCallback(
(e) => {
e.preventDefault();
onRemove(marker._id);
onRemove(marker.id);
},
[marker._id, onRemove]
[marker.id, onRemove]
);

return (
Expand Down
11 changes: 6 additions & 5 deletions components/bal/toponyme-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function ToponymeEditor({
if (markers) {
markers.forEach((marker) => {
body.positions.push({
id: marker.id,
point: {
type: "Point",
coordinates: [marker.longitude, marker.latitude],
Expand All @@ -85,15 +86,15 @@ function ToponymeEditor({
// Add or edit a toponyme
const submit = initialValue
? toaster(
() => ToponymesService.updateToponyme(initialValue._id, body),
() => ToponymesService.updateToponyme(initialValue.id, body),
"Le toponyme a bien été modifé",
"Le toponyme n’a pas pu être modifié",
(error) => {
setValidationMessages(error.body.message);
}
)
: toaster(
() => BasesLocalesService.createToponyme(baseLocale._id, body),
() => BasesLocalesService.createToponyme(baseLocale.id, body),
"Le toponyme a bien été ajouté",
"Le toponyme n’a pas pu être ajouté",
(error) => {
Expand All @@ -105,7 +106,7 @@ function ToponymeEditor({

refreshBALSync();

if (initialValue?._id === toponyme._id && router.query.idToponyme) {
if (initialValue?.id === toponyme.id && router.query.idToponyme) {
setToponyme(toponyme);
}

Expand All @@ -127,7 +128,7 @@ function ToponymeEditor({
}
},
[
baseLocale._id,
baseLocale.id,
initialValue,
nom,
nomAlt,
Expand Down Expand Up @@ -168,7 +169,7 @@ function ToponymeEditor({

return (
<Form
editingId={initialValue?._id}
editingId={initialValue?.id}
closeForm={closeForm}
onFormSubmit={onFormSubmit}
>
Expand Down
10 changes: 5 additions & 5 deletions components/bal/toponymes-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ function ToponymesList({

<InfiniteScrollList items={scrollableItems}>
{(toponyme: ExtentedToponymeDTO & { commentedNumeros: Numero[] }) => (
<Table.Row key={toponyme._id} paddingRight={8} minHeight={48}>
<Table.Row key={toponyme.id} paddingRight={8} minHeight={48}>
<Table.Cell
onClick={() => onSelect(toponyme._id)}
onClick={() => onSelect(toponyme.id)}
cursor="pointer"
className="main-table-cell"
>
Expand Down Expand Up @@ -181,13 +181,13 @@ function ToponymesList({
{isEditingEnabled && (
<TableRowActions
onSelect={() => {
onSelect(toponyme._id);
onSelect(toponyme.id);
}}
onEdit={() => {
onEnableEditing(toponyme._id);
onEnableEditing(toponyme.id);
}}
onRemove={() => {
setToRemove(toponyme._id);
setToRemove(toponyme.id);
}}
/>
)}
Expand Down
13 changes: 5 additions & 8 deletions components/bal/voie-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ function VoieEditor({
const submit = initialValue
? toaster(
async () =>
VoiesService.updateVoie(
initialValue._id,
body as UpdateVoieDTO
),
VoiesService.updateVoie(initialValue.id, body as UpdateVoieDTO),
"La voie a bien été modifiée",
"La voie n’a pas pu être modifiée",
(err) => {
Expand All @@ -85,7 +82,7 @@ function VoieEditor({
: toaster(
async () =>
BasesLocalesService.createVoie(
baseLocale._id,
baseLocale.id,
body as CreateVoieDTO
),
"La voie a bien été ajoutée",
Expand All @@ -99,7 +96,7 @@ function VoieEditor({

refreshBALSync();

if (initialValue?._id === voie._id && router.query.idVoie) {
if (initialValue?.id === voie.id && router.query.idVoie) {
setVoie(voie);
// Reload voie trace
if (
Expand All @@ -126,7 +123,7 @@ function VoieEditor({
}
},
[
baseLocale._id,
baseLocale.id,
initialValue,
nom,
isMetric,
Expand Down Expand Up @@ -175,7 +172,7 @@ function VoieEditor({

return (
<Form
editingId={initialValue?._id}
editingId={initialValue?.id}
unmountForm={onUnmount}
closeForm={closeForm}
onFormSubmit={onFormSubmit}
Expand Down
12 changes: 6 additions & 6 deletions components/bal/voies-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ function VoiesList({

<InfiniteScrollList items={scrollableItems}>
{(voie: ExtendedVoieDTO & { commentedNumeros: Numero[] }) => (
<Table.Row key={voie._id} paddingRight={8} minHeight={48}>
<Table.Row key={voie.id} paddingRight={8} minHeight={48}>
<Table.Cell
onClick={() => onSelect(voie._id)}
onClick={() => onSelect(voie.id)}
cursor="pointer"
className="main-table-cell"
>
Expand Down Expand Up @@ -207,19 +207,19 @@ function VoiesList({
{isEditingEnabled && (
<TableRowActions
onSelect={() => {
onSelect(voie._id);
onSelect(voie.id);
}}
onEdit={() => {
onEnableEditing(voie._id);
onEnableEditing(voie.id);
}}
onRemove={() => {
setToRemove(voie._id);
setToRemove(voie.id);
}}
extra={
voie.nbNumeros === 0
? {
callback: () => {
setToConvert(voie._id);
setToConvert(voie.id);
},
icon: KeyTabIcon,
text: "Convertir en toponyme",
Expand Down
Loading

0 comments on commit 3c7b339

Please sign in to comment.