chore(server): Move api-server in to it's own DIR
This commit is contained in:
committed by
mrugesh mohapatra
parent
9fba6bce4c
commit
46a217d0a5
30
api-server/server/models/about.js
Normal file
30
api-server/server/models/about.js
Normal file
@ -0,0 +1,30 @@
|
||||
import { createActiveUsers } from '../utils/about.js';
|
||||
|
||||
|
||||
module.exports = function(About) {
|
||||
const activeUsers = createActiveUsers();
|
||||
let activeUsersForRendering = 0;
|
||||
About.getActiveUsers = async function getActiveUsers() {
|
||||
// converting to promise automatically will subscribe to Observable
|
||||
// initiating the sequence above
|
||||
const usersActive = await activeUsers.toPromise();
|
||||
activeUsersForRendering = usersActive;
|
||||
return usersActive;
|
||||
};
|
||||
|
||||
About.getActiveUsersForRendering = () => activeUsersForRendering;
|
||||
|
||||
About.remoteMethod(
|
||||
'getActiveUsers',
|
||||
{
|
||||
http: {
|
||||
path: '/get-active-users',
|
||||
verb: 'get'
|
||||
},
|
||||
returns: {
|
||||
type: 'number',
|
||||
arg: 'activeUsers'
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
28
api-server/server/models/about.json
Normal file
28
api-server/server/models/about.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "about",
|
||||
"plural": "about",
|
||||
"base": "PersistedModel",
|
||||
"idInjection": true,
|
||||
"options": {
|
||||
"validateUpsert": true
|
||||
},
|
||||
"properties": {},
|
||||
"validations": [],
|
||||
"relations": {},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "EXECUTE",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW",
|
||||
"property": "getActiveUsers"
|
||||
}
|
||||
],
|
||||
"methods": {}
|
||||
}
|
15
api-server/server/models/auth-token.js
Normal file
15
api-server/server/models/auth-token.js
Normal file
@ -0,0 +1,15 @@
|
||||
import { Observable } from 'rx';
|
||||
|
||||
export default function(AuthToken) {
|
||||
AuthToken.on('dataSourceAttached', () => {
|
||||
AuthToken.findOne$ = Observable.fromNodeCallback(
|
||||
AuthToken.findOne.bind(AuthToken)
|
||||
);
|
||||
AuthToken.prototype.validate$ = Observable.fromNodeCallback(
|
||||
AuthToken.prototype.validate
|
||||
);
|
||||
AuthToken.prototype.destroy$ = Observable.fromNodeCallback(
|
||||
AuthToken.prototype.destroy
|
||||
);
|
||||
});
|
||||
}
|
13
api-server/server/models/auth-token.json
Normal file
13
api-server/server/models/auth-token.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "AuthToken",
|
||||
"base": "AccessToken",
|
||||
"idInjection": true,
|
||||
"options": {
|
||||
"validateUpsert": true
|
||||
},
|
||||
"properties": {},
|
||||
"validations": [],
|
||||
"relations": {},
|
||||
"acls": [],
|
||||
"methods": {}
|
||||
}
|
15
api-server/server/models/donation.js
Normal file
15
api-server/server/models/donation.js
Normal file
@ -0,0 +1,15 @@
|
||||
import { Observable } from 'rx';
|
||||
|
||||
export default function(Donation) {
|
||||
Donation.on('dataSourceAttached', () => {
|
||||
Donation.findOne$ = Observable.fromNodeCallback(
|
||||
Donation.findOne.bind(Donation)
|
||||
);
|
||||
Donation.prototype.validate$ = Observable.fromNodeCallback(
|
||||
Donation.prototype.validate
|
||||
);
|
||||
Donation.prototype.destroy$ = Observable.fromNodeCallback(
|
||||
Donation.prototype.destroy
|
||||
);
|
||||
});
|
||||
}
|
68
api-server/server/models/donation.json
Normal file
68
api-server/server/models/donation.json
Normal file
@ -0,0 +1,68 @@
|
||||
{
|
||||
"name": "Donation",
|
||||
"description": "A representaion of a donation to freeCodeCamp",
|
||||
"plural": "donations",
|
||||
"base": "PersistedModel",
|
||||
"idInjection": true,
|
||||
"scopes": {},
|
||||
"indexes": {},
|
||||
"options": {
|
||||
"validateUpsert": true
|
||||
},
|
||||
"hidden": [],
|
||||
"remoting": {},
|
||||
"http": {},
|
||||
"properties": {
|
||||
"email": {
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "The email used to create the donation"
|
||||
},
|
||||
"provider": {
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "The payment handler, paypal/stripe etc..."
|
||||
},
|
||||
"amount": {
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "The donation amount in cents"
|
||||
},
|
||||
"startDate": {
|
||||
"type": "DateString",
|
||||
"required": true
|
||||
},
|
||||
"endDate": {
|
||||
"type": "DateString"
|
||||
},
|
||||
"subscriptionId": {
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "The donation subscription id returned from the provider"
|
||||
},
|
||||
"customerId": {
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "The providers reference for the donator"
|
||||
}
|
||||
},
|
||||
"validations": [
|
||||
{
|
||||
"amount": {
|
||||
"type": "number",
|
||||
"description": "Amount should be >= $1 (100c)",
|
||||
"min": 100
|
||||
},
|
||||
"facetName": "server"
|
||||
}
|
||||
],
|
||||
"relations": {
|
||||
"user": {
|
||||
"type": "belongsTo",
|
||||
"model": "user",
|
||||
"foreignKey": "userId"
|
||||
}
|
||||
},
|
||||
"acls": [],
|
||||
"methods": {}
|
||||
}
|
Reference in New Issue
Block a user