Skip to content

Commit

Permalink
WIP: Add script to import CSV data to DatoCMS
Browse files Browse the repository at this point in the history
  • Loading branch information
Siilwyn committed Oct 25, 2023
1 parent 2949deb commit 051fd14
Show file tree
Hide file tree
Showing 11 changed files with 1,007 additions and 926 deletions.
734 changes: 551 additions & 183 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,19 @@
"vue-virtual-scroller": "^2.0.0-beta.8"
},
"devDependencies": {
"@datocms/cma-client-node": "^2.0.0",
"@types/js-cookie": "^3.0.3",
"@types/mapbox-gl": "^2.7.10",
"@types/node": "^18.14.1",
"@typescript-eslint/parser": "^5.54.0",
"cypress": "^12.7.0",
"dotenv": "^16.3.1",
"eslint": "^8.35.0",
"eslint-plugin-vue": "^9.9.0",
"husky": "^8.0.3",
"nano-staged": "^0.8.0",
"supabase": "^1.41.6",
"vitest": "^0.29.2"
"vitest": "^0.34.4"
},
"overrides": {
"vue": "latest"
Expand Down
68 changes: 39 additions & 29 deletions scripts/data/cms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ async function getFromDato(query: string, rootProp: string) {
method: "POST",
headers: {
Authorization: `Bearer ${DATO_API_TOKEN}`,
"X-Environment": "selwyns-testing-ground",
},
body: JSON.stringify({ query }),
})
Expand All @@ -21,16 +22,46 @@ export function getBuildingsDataFromCms() {
return import("../../../mock/cms/buildings.json").then((data) => data.default);
}
return getFromDato(
`{
allBuildings {
image {
url
`
{
allBuildings(first: 100) {
number
nameEN: name(locale: en)
nameNL: name(locale: nl)
abbreviationEN: abbreviation(locale: en)
abbreviationNL: abbreviation(locale: nl)
occupancyLimit
bounds
image {
url
}
spaces: _allReferencingSpaces {
spaceId
roomId
nameEN: name(locale: en)
nameNL: name(locale: nl)
floor
location {
latitude
longitude
}
image {
url
}
seats
quietness
adjustableChairs
daylit
powerOutlets
whiteBoard
presentationScreen
nearCoffeeMachine
nearPrinter
nearBathroom
}
}
number
occupancyLimit
bounds
}
}`,
`,
"allBuildings"
);
}
Expand Down Expand Up @@ -75,27 +106,6 @@ export function getNotificationFromCms(): Promise<DatoNotification> {
);
}

export function getSpacesDataFromCms() {
if (mockDataEnabled)
return import("../../../mock/cms/spaces.json").then((info) => info.default);

return getFromDato(
`{
allSpaces {
spaceId
_allMessageLocales {
locale
value
}
image {
url
}
}
}`,
"allSpaces"
);
}

export interface DatoLocalizedContent {
locale: string;
value: string;
Expand Down
130 changes: 0 additions & 130 deletions scripts/data/csv/config.ts

This file was deleted.

1 change: 0 additions & 1 deletion scripts/data/csv/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test, expect } from "vitest";
import { buildingNumberFromId } from "./index";

test("parse the building number from a building id", () => {
let result = buildingNumberFromId("04 - some building name");
Expand Down
Loading

0 comments on commit 051fd14

Please sign in to comment.