Signup endpoints almost done
This commit is contained in:
10
src/models/api/API.js
Normal file
10
src/models/api/API.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import {BaseAPI} from './baseAPI';
|
||||
|
||||
export class API extends BaseAPI {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
API.errors = require('./APIErrors').APIErrors;
|
||||
API.user = require('./userResponses').User;
|
||||
39
src/models/api/APIErrors.js
Normal file
39
src/models/api/APIErrors.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import {API} from './API';
|
||||
|
||||
export class APIErrors extends API {
|
||||
// get errors() {return this.errors}
|
||||
// set errors(err) {this.errors = err}
|
||||
|
||||
constructor(res) {
|
||||
super()
|
||||
this.res = res;
|
||||
this.errors = {
|
||||
status: {
|
||||
error: true,
|
||||
code: undefined,
|
||||
type: undefined,
|
||||
message: undefined
|
||||
},
|
||||
error: {
|
||||
errors: []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addError(statusCode, message, verbose) {
|
||||
this.errors.error.errors.push({status: statusCode, title: message, detail: verbose});
|
||||
this.errors.status.code = statusCode;
|
||||
this.errors.status.type = message;
|
||||
this.errors.status.message = verbose;
|
||||
}
|
||||
|
||||
count() {
|
||||
return this.errors.error.errors.length;
|
||||
}
|
||||
|
||||
endpoint() {
|
||||
this.res.setHeader('Content-type', 'application/json');
|
||||
this.res.status(this.errors.status.code);
|
||||
this.res.end(JSON.stringify(this.errors, false, 4));
|
||||
}
|
||||
}
|
||||
4
src/models/api/baseAPI.js
Normal file
4
src/models/api/baseAPI.js
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
export class BaseAPI {
|
||||
constructor() { }
|
||||
}
|
||||
34
src/models/api/userResponses.js
Normal file
34
src/models/api/userResponses.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import {API} from './API';
|
||||
|
||||
export class User extends API {
|
||||
constructor(res, id, username, email, updated, token) {
|
||||
super();
|
||||
this.res = res;
|
||||
this.response = {
|
||||
status: {
|
||||
error: false,
|
||||
code: 200,
|
||||
type: 'success',
|
||||
message: 'Success'
|
||||
},
|
||||
data: [
|
||||
{
|
||||
status: 'Authenticated',
|
||||
user: {
|
||||
id: id,
|
||||
username: username,
|
||||
email: email,
|
||||
updated: updated
|
||||
},
|
||||
token: token
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
endpoint() {
|
||||
this.res.setHeader('Content-type', 'application/json');
|
||||
this.res.status(200);
|
||||
this.res.end(JSON.stringify(this.response, false, 4));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user