2023-12-19 16:59:23 +01:00
|
|
|
#!/bin/node
|
|
|
|
const { createApp, getTable, createRow, createTable } = require("./utils")
|
|
|
|
|
2023-12-20 11:51:35 +01:00
|
|
|
const Chance = require("chance")
|
|
|
|
const generator = new Chance()
|
|
|
|
|
2023-12-20 12:18:29 +01:00
|
|
|
const STUDENT_COUNT = 10
|
|
|
|
const SUBJECT_COUNT = 10
|
2023-12-19 16:59:23 +01:00
|
|
|
|
|
|
|
if (!process.argv[2]) {
|
|
|
|
console.error("Please specify an API key as script argument.")
|
|
|
|
process.exit(-1)
|
|
|
|
}
|
|
|
|
|
2023-12-20 12:18:29 +01:00
|
|
|
async function sleep(ms) {
|
|
|
|
return new Promise(r => setTimeout(() => r(), ms))
|
|
|
|
}
|
|
|
|
|
2023-12-19 16:59:23 +01:00
|
|
|
async function run() {
|
|
|
|
const apiKey = process.argv[2]
|
|
|
|
const app = await createApp(apiKey)
|
|
|
|
console.log(`App created: ${app._id}`)
|
2023-12-20 12:18:29 +01:00
|
|
|
const studentsTable = await getTable(apiKey, app._id)
|
|
|
|
if (studentsTable.name !== "Students") {
|
|
|
|
throw 'Fetched table should be "Students"'
|
|
|
|
}
|
|
|
|
console.log(`Table found: ${studentsTable.name}`)
|
2023-12-19 16:59:23 +01:00
|
|
|
|
|
|
|
const subjectTable = await createTable(apiKey, app._id, {
|
|
|
|
schema: {
|
2023-12-20 11:51:35 +01:00
|
|
|
Name: {
|
2023-12-19 16:59:23 +01:00
|
|
|
name: "Name",
|
|
|
|
type: "string",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
name: "Subjects",
|
|
|
|
})
|
2023-12-20 11:51:35 +01:00
|
|
|
|
|
|
|
for (let i = 0; i < SUBJECT_COUNT; i++) {
|
|
|
|
await createRow(apiKey, app._id, subjectTable, {
|
|
|
|
Name: generator.profession(),
|
|
|
|
})
|
|
|
|
console.log(`Subject ${i + 1} of ${SUBJECT_COUNT} created`)
|
2023-12-20 12:18:29 +01:00
|
|
|
await sleep(50)
|
2023-12-19 16:59:23 +01:00
|
|
|
}
|
|
|
|
|
2023-12-20 12:18:29 +01:00
|
|
|
for (let i = 0; i < STUDENT_COUNT; i++) {
|
|
|
|
await createRow(apiKey, app._id, studentsTable)
|
|
|
|
console.log(`Row ${i + 1} of ${STUDENT_COUNT} created`)
|
2023-12-19 16:59:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`App created: http://localhost:10000/builder/app/${app._id}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
run()
|
|
|
|
.then(() => {
|
|
|
|
console.log(`Finished creating ${ROW_COUNT} rows.`)
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.error(err)
|
|
|
|
})
|