diff --git a/package-lock.json b/package-lock.json index f4cc13e..e577b88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,8 @@ "koa": "^2.13.4", "koa-bodyparser": "^4.3.0", "koa-router": "^10.1.1", - "promise-mysql": "^5.0.4" + "promise-mysql": "^5.0.4", + "uuid": "^8.3.2" } }, "node_modules/@types/bluebird": { @@ -686,6 +687,14 @@ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -1221,6 +1230,11 @@ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index f72da13..ea83c23 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "koa": "^2.13.4", "koa-bodyparser": "^4.3.0", "koa-router": "^10.1.1", - "promise-mysql": "^5.0.4" + "promise-mysql": "^5.0.4", + "uuid": "^8.3.2" } } diff --git a/schemas/user.json b/schemas/user.json new file mode 100644 index 0000000..b571f44 --- /dev/null +++ b/schemas/user.json @@ -0,0 +1,170 @@ +"$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + + + "user": { + "$id": "#user", + "title": "User", + "description": "Data to register a new user.", + "type": "object", + "properties": { + "firstName": { + "description": "First name", + "type": "string" + }, + "lastName": { + "description": "Last name", + "type": "string" + }, + "about": { + "description": "Description of the user", + "type": "string" + }, + "email": { + "description": "Unique email address", + "type": "string", + "format": "email" + }, + "avatarURL": { + "description": "URL of avatar image", + "type": "string", + "format": "uri" + }, + "username": { + "description": "Unique username", + "type": "string", + "minLength": 3 + }, + "password": { + "description": "Password for registration", + "type": "string", + "minLength": 6 + } + }, + "required": ["username", "email", "password"], + "additionalProperties": false + }, + + + "userView": { + "$id": "#userView", + "title": "User View", + "description": "Data visible to users and admins (excludes password).", + "type": "object", + "properties": { + "firstName": { + "description": "First name", + "type": "string" + }, + "lastName": { + "description": "Last name", + "type": "string" + }, + "about": { + "description": "Description of the user", + "type": "string" + }, + "email": { + "description": "Unique email address", + "type": "string" + }, + "avatarURL": { + "description": "URL of avatar image", + "type": "string" + }, + "username": { + "description": "Unique username", + "type": "string" + } + } + }, + + + "userUpdate": { + "$id": "#userUpdate", + "title": "User Update", + "description": "Data a user can update (excludes username).", + "type": "object", + "properties": { + "firstName": { + "description": "First name", + "type": "string" + }, + "lastName": { + "description": "Last name", + "type": "string" + }, + "about": { + "description": "Description of the user", + "type": "string" + }, + "email": { + "description": "Unique email address", + "type": "string", + "format": "email" + }, + "avatarURL": { + "description": "URL of avatar image", + "type": "string", + "format": "uri" + }, + "password": { + "description": "Password for registration", + "type": "string", + "minLength": 6 + } + }, + "additionalProperties": false + }, + + + "userList": { + "$id": "#userList", + "title": "User List", + "description": "List of all users visible to admin only.", + "type": "array", + "items": {"$ref": "#/definitions/userView"} + }, + + + "userUpdated": { + "$id": "#userUpdated", + "title": "User Updated", + "description": "Confirmation of a successful user update/creation", + "type": "object", + "properties": { + "ID": { + "description": "ID of the updated user record", + "type": "integer" + }, + "updated": { + "description": "Boolean indicator of success", + "type": "boolean" + }, + "link": { + "description": "Path to retrieve user record", + "type": "string", + "format": "uri" + } + } + }, + + + "userDeleted": { + "$id": "#userDeleted", + "title": "User Deleted", + "description": "Confirmation of a successful deletion", + "type": "object", + "properties": { + "ID": { + "description": "ID of the updated user record", + "type": "integer" + }, + "deleted": { + "description": "Boolean indicator of success", + "type": "boolean" + } + } + } + } +}