diff --git a/ack.bak b/ack.bak new file mode 100644 index 0000000..4b4d46c --- /dev/null +++ b/ack.bak @@ -0,0 +1,43 @@ +let { readFileSync } = require('fs') +const $RefParser = require('@apidevtools/json-schema-ref-parser') +/* +function generateSchemaId(schemaId) { + let id = null + if (schemaId.startsWith('http')) { + let tmpUrl = new URL(schemaId) + id = tmpUrl.pathname + } else { + id = schemaId + } + return id.split('/').pop() +} + +const schema = JSON.parse(readFileSync('./customer.schema.json')) + +if (!schema.id && schema['$id']) { + schema.id = schema['$id'] +} + +const id = generateSchemaId(schema.id) + +console.log(id) +console.log(generateSchemaId('/schemas/customer')) +console.log(generateSchemaId('person')) +*/ + +async function ack () { + const schema = JSON.parse(readFileSync('./game.schema.json')) + try { + let myschema = await $RefParser.dereference(schema) + console.log(JSON.stringify(myschema, null, 2)) + } + catch (err) { + console.error(err) + } +} + +ack() + +// console.log(schema) + + diff --git a/commands.txt b/commands.txt new file mode 100644 index 0000000..082b013 --- /dev/null +++ b/commands.txt @@ -0,0 +1,24 @@ +// create + +curl -X POST http://localhost:3333/accounts \ + -H 'Content-Type: application/json' \ + -d '{"email":"simon@begin.com","password":"my_password", "url": "https://begin.com", "tel": "1234"}' + +// update + +curl -X POST http://localhost:3333/accounts/pV4yAGkPfz \ + -H 'Content-Type: application/json' \ + -d '{"email":"me@begin.com","password":"my_password", "url": "https://begin.com", "tel": "1234"}' + +// delete + +curl -X POST http://localhost:3333/accounts/pV4yAGkPfz/delete \ + -H 'Content-Type: application/json' + + // Insert your custom validation here + let accounts = await data.get({ + table: 'accounts' + }) + if (accounts.find(account => account.email === req.body.email)) { + problems.push('Email address already exists in database') + } diff --git a/game.schema.json b/game.schema.json new file mode 100644 index 0000000..0844152 --- /dev/null +++ b/game.schema.json @@ -0,0 +1,32 @@ +{ + "id": "Game", + "$id": "Game", + "type": "object", + "required": [ + "date", "time", "facility" + ], + "properties": { + "date": { + "type": "string", + "format": "date" + }, + "time": { + "type": "string", + "format": "time" + }, + "facility": { + "type": "string" + }, + "players": { + "type": "array", + "items": { + "$ref": "#/definitions/Player" + } + } + }, + "definitions": { + "Player": { + "$ref": "player.schema.json" + } + } +} diff --git a/player.schema.json b/player.schema.json new file mode 100644 index 0000000..49dac8d --- /dev/null +++ b/player.schema.json @@ -0,0 +1,33 @@ +{ + "id": "Player", + "$id": "Player", + "type": "object", + "required": [ + "name", "email", "position" + ], + "properties": { + "name": { + "type": "string" + }, + "email": { + "type": "string", + "format": "email" + }, + "phone": { + "type": "string", + "format": "tel" + }, + "position": { + "type": "string", + "enum": [ + "Defence", + "Forward", + "Goalie", + "Skater" + ] + }, + "fulltime": { + "type": "boolean" + } + } + } diff --git a/src/commands/create/action.js b/src/commands/create/action.js index 3f93669..0747f51 100644 --- a/src/commands/create/action.js +++ b/src/commands/create/action.js @@ -34,6 +34,7 @@ module.exports = async function action (params, utils) { } catch (err) { if (err.message === 'app_not_found') return Error(`No app found with app ID '${appID}'`) + if (err.message === 'unknown_error') return Error(`No app found with app ID '${appID}' or the user does not have permission to access the app.`) return } let envs = app.environments diff --git a/src/commands/deploy/action.js b/src/commands/deploy/action.js index 909b853..64f2169 100644 --- a/src/commands/deploy/action.js +++ b/src/commands/deploy/action.js @@ -16,7 +16,14 @@ module.exports = async function action (params, utils) { // Go get the app (if we didn't just create one) if (!app) { - app = await client.find({ token, appID, _staging }) + try { + app = await client.find({ token, appID, _staging }) + } + catch (err) { + if (err.message === 'app_not_found') return Error(`No app found with app ID '${appID}'`) + if (err.message === 'unknown_error') return Error(`No app found with app ID '${appID}' or the user does not have permission to access the app.`) + return + } } let envs = app.environments