Reuse subjects

This commit is contained in:
Adria Navarro 2023-12-22 12:18:24 +01:00
parent bd221f2727
commit 5a45249ad4
2 changed files with 17 additions and 8 deletions

View File

@ -5,6 +5,7 @@ const {
createRow,
createTable,
getApp,
getRows,
} = require("./utils")
const Chance = require("chance")
@ -122,14 +123,16 @@ async function run() {
primaryDisplay: "Name",
})
const subjects = await batchCreate(
apiKey,
appId,
subjectTable,
Array.from({ length: SUBJECT_COUNT }).map(() => ({
Name: generator.profession(),
}))
)
const subjects = useExistingApp
? await getRows(apiKey, appId, subjectTable._id)
: await batchCreate(
apiKey,
appId,
subjectTable,
Array.from({ length: SUBJECT_COUNT }).map(() => ({
Name: generator.profession(),
}))
)
const gradesTable = await upsertTable(appId, "Grades", {
schema: {

View File

@ -88,6 +88,12 @@ exports.createRow = async (apiKey, appId, table, body) => {
return (await res.json()).data
}
exports.getRows = async (apiKey, appId, tableId) => {
const url = `${URL_TABLE}/${tableId}/rows/search`
const res = await request(apiKey, url, "POST", {}, appId)
return (await res.json()).data
}
exports.createTable = async (apiKey, appId, config) => {
const res = await request(apiKey, URL_TABLE, "POST", config, appId)
const json = await res.json()