diff --git a/insertions/script.mjs b/insertions/script.mjs index ad89a8c56e77cb166a5dd5fcf4c29e09d403eecf..2202714d37c60b68674f64e17c9c14c391643b1d 100644 --- a/insertions/script.mjs +++ b/insertions/script.mjs @@ -104,12 +104,11 @@ const matches = { "976": "Mayotte" }; -const argv = process.argv.slice(2); -if (argv.length !== 1) { +const [node, self, file] = process.argv; +if (file == null) { console.error(`Usage : node script.mjs `); process.exit(1); } -const file = argv[0]; const fileContent = readFileSync(file, { encoding: "utf8", flag: "r" @@ -117,8 +116,9 @@ const fileContent = readFileSync(file, { let str = `INSERT INTO ma_table(date, value, region, surface) VALUES\n`; let idx = 0; -for (const line of fileContent.slice(1, fileContent.length - 1)) { +for (const line of fileContent.slice(1, fileContent.length)) { const data = line.split("|"); + if (data.length === 0) continue; const date = data[8].split("/").reverse().join("-"); if (data[9] === "Vente" && data[10] !== "" && data[38] !== "" && (data[36] === "Maison" || data[36] === "Appartement")) { str += `('${date}', ${data[10].replace(",", ".")}, '${matches[data[18]].replace("'", "''")}', ${data[38]})${idx < fileContent.length - 3 ? ",\n" : ";"}`; diff --git a/pwa/components/book/Form.tsx b/pwa/components/book/Form.tsx deleted file mode 100644 index 33d43d94a3b94235aae2e251412013f05c07e776..0000000000000000000000000000000000000000 --- a/pwa/components/book/Form.tsx +++ /dev/null @@ -1,344 +0,0 @@ -import { FunctionComponent, useState } from "react"; -import Link from "next/link"; -import { useRouter } from "next/router"; -import { ErrorMessage, Field, FieldArray, Formik } from "formik"; -import { useMutation } from "react-query"; - -import { fetch, FetchError, FetchResponse } from "../../utils/dataAccess"; -import { Book } from "../../types/Book"; - -interface Props { - book?: Book; -} - -interface SaveParams { - values: Book; -} - -interface DeleteParams { - id: string; -} - -const saveBook = async ({ values }: SaveParams) => - await fetch(!values["@id"] ? "/books" : values["@id"], { - method: !values["@id"] ? "POST" : "PUT", - body: JSON.stringify(values), - }); - -const deleteBook = async (id: string) => - await fetch(id, { method: "DELETE" }); - -export const Form: FunctionComponent = ({ book }) => { - const [, setError] = useState(null); - const router = useRouter(); - - const saveMutation = useMutation< - FetchResponse | undefined, - Error | FetchError, - SaveParams - >((saveParams) => saveBook(saveParams)); - - const deleteMutation = useMutation< - FetchResponse | undefined, - Error | FetchError, - DeleteParams - >(({ id }) => deleteBook(id), { - onSuccess: () => { - router.push("/books"); - }, - onError: (error) => { - setError(`Error when deleting the resource: ${error}`); - console.error(error); - }, - }); - - const handleDelete = () => { - if (!book || !book["@id"]) return; - if (!window.confirm("Are you sure you want to delete this item?")) return; - deleteMutation.mutate({ id: book["@id"] }); - }; - - return ( -
- - {`< Back to list`} - -

- {book ? `Edit Book ${book["@id"]}` : `Create Book`} -

- { - const errors = {}; - // add your validation logic here - return errors; - }} - onSubmit={(values, { setSubmitting, setStatus, setErrors }) => { - const isCreation = !values["@id"]; - saveMutation.mutate( - { values }, - { - onSuccess: () => { - setStatus({ - isValid: true, - msg: `Element ${isCreation ? "created" : "updated"}.`, - }); - router.push("/books"); - }, - onError: (error) => { - setStatus({ - isValid: false, - msg: `${error.message}`, - }); - if ("fields" in error) { - setErrors(error.fields); - } - }, - onSettled: () => { - setSubmitting(false); - }, - } - ); - }} - > - {({ - values, - status, - errors, - touched, - handleChange, - handleBlur, - handleSubmit, - isSubmitting, - }) => ( -
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
-
- reviews -
- ( -
- {values.reviews && values.reviews.length > 0 ? ( - values.reviews.map((item: any, index: number) => ( -
- - - -
- )) - ) : ( - - )} -
- )} - /> -
- {status && status.msg && ( -
- {status.msg} -
- )} - -
- )} -
-
- {book && ( - - )} -
-
- ); -}; diff --git a/pwa/components/book/List.tsx b/pwa/components/book/List.tsx deleted file mode 100644 index d7fec9a58214c9d9a29f3c676b5e7ca89bf54e05..0000000000000000000000000000000000000000 --- a/pwa/components/book/List.tsx +++ /dev/null @@ -1,111 +0,0 @@ -import { FunctionComponent } from "react"; -import Link from "next/link"; - -import ReferenceLinks from "../common/ReferenceLinks"; -import { getItemPath } from "../../utils/dataAccess"; -import { Book } from "../../types/Book"; - -interface Props { - books: Book[]; -} - -export const List: FunctionComponent = ({ books }) => ( -
-
-

Book List

- - Create - -
- - - - - - - - - - - - - - {books && - books.length !== 0 && - books.map( - (book) => - book["@id"] && ( - - - - - - - - - - - - ) - )} - -
idisbntitledescriptionauthorpublicationDatereviews -
- - {book["isbn"]}{book["title"]}{book["description"]}{book["author"]}{book["publicationDate"]?.toLocaleString()} - ({ - href: getItemPath(ref, "/reviews/[id]"), - name: ref, - }))} - /> - - - Show - - - - - - - - Edit - - - - - -
-
-); diff --git a/pwa/components/book/PageList.tsx b/pwa/components/book/PageList.tsx deleted file mode 100644 index 177e7075b5c3b69bfaed2b60604041e0b44df655..0000000000000000000000000000000000000000 --- a/pwa/components/book/PageList.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import { NextComponentType, NextPageContext } from "next"; -import { useRouter } from "next/router"; -import Head from "next/head"; -import { useQuery } from "react-query"; - -import Pagination from "../common/Pagination"; -import { List } from "./List"; -import { PagedCollection } from "../../types/collection"; -import { Book } from "../../types/Book"; -import { fetch, FetchResponse, parsePage } from "../../utils/dataAccess"; -import { useMercure } from "../../utils/mercure"; - -export const getBooksPath = (page?: string | string[] | undefined) => - `/books${typeof page === "string" ? `?page=${page}` : ""}`; -export const getBooks = (page?: string | string[] | undefined) => async () => - await fetch>(getBooksPath(page)); -const getPagePath = (path: string) => `/books/page/${parsePage("books", path)}`; - -export const PageList: NextComponentType = () => { - const { - query: { page }, - } = useRouter(); - const { data: { data: books, hubURL } = { hubURL: null } } = useQuery< - FetchResponse> | undefined - >(getBooksPath(page), getBooks(page)); - const collection = useMercure(books, hubURL); - - if (!collection || !collection["hydra:member"]) return null; - - return ( -
-
- - Book List - -
- - -
- ); -}; diff --git a/pwa/components/book/Show.tsx b/pwa/components/book/Show.tsx deleted file mode 100644 index c9ead29b8a1951c5efd229e1658e8309263925c5..0000000000000000000000000000000000000000 --- a/pwa/components/book/Show.tsx +++ /dev/null @@ -1,116 +0,0 @@ -import { FunctionComponent, useState } from "react"; -import Link from "next/link"; -import { useRouter } from "next/router"; -import Head from "next/head"; - -import ReferenceLinks from "../common/ReferenceLinks"; -import { fetch, getItemPath } from "../../utils/dataAccess"; -import { Book } from "../../types/Book"; - -interface Props { - book: Book; - text: string; -} - -export const Show: FunctionComponent = ({ book, text }) => { - const [error, setError] = useState(null); - const router = useRouter(); - - const handleDelete = async () => { - if (!book["@id"]) return; - if (!window.confirm("Are you sure you want to delete this item?")) return; - - try { - await fetch(book["@id"], { method: "DELETE" }); - router.push("/books"); - } catch (error) { - setError("Error when deleting the resource."); - console.error(error); - } - }; - - return ( -
- - {`Show Book ${book["@id"]}`} -