Reuse subjects
This commit is contained in:
parent
bd221f2727
commit
5a45249ad4
|
@ -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: {
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue