Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

Commit

Permalink
added: project files
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Jan 31, 2019
1 parent 16179d5 commit 18ea9e4
Show file tree
Hide file tree
Showing 75 changed files with 7,028 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
28 changes: 28 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
PORT=33000
TZ=UTC
ENV=production
SERVICE_USER=
SERVICE_GROUP=

DB_PROD_HOST=
DB_PROD_USER=
DB_PROD_PASS=
DB_PROD_DB=

DB_TEST_HOST=
DB_TEST_USER=
DB_TEST_PASS=
DB_TEST_DB=


DB_DEV_HOST=
DB_DEV_USER=
DB_DEV_PASS=
DB_DEV_DB=

SENTRY_DSN=https://{PUBLIC_KEY}@sentry.io/{PROJECT_ID}

APIDOCS_DOMAIN=apidocs.example.com

FREE_SMS_API_USER=
FREE_SMS_API_PASS=
3 changes: 3 additions & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
public
apidocs
20 changes: 20 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"strict": true,
"curly": true,
"quotmark": "simple",
"esversion": 6,
"browser": false,
"mocha": true,
"node": true,
"noempty": true,
"debug": false,
"globals": {
"logger": false,
"app": false,
"cluster": false,
"sequelize": false,
"Sentry": false,
"queue": false,
"smsQueue": false
}
}
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
public
apidocs
coverage
8 changes: 8 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require('path');

module.exports = {
'config': path.resolve('config', 'db.js'),
'models-path': path.resolve('db', 'models'),
'seeders-path': path.resolve('db', 'seeders'),
'migrations-path': path.resolve('db', 'migrations')
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# stats
Wdes stats
# wdes-stats
WdesStats server
2 changes: 2 additions & 0 deletions apidocs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*
!.gitignore
57 changes: 57 additions & 0 deletions config/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require('dotenv').config({ path: __dirname + '/../.env' });

const pool = {
max: 5,
min: 0,
acquire: 30000,
idle: 10000,
};

const define = {
underscored: false,
freezeTableName: false,
charset: 'utf8',
dialectOptions: {
collate: 'utf8_general_ci',
},
timestamps: true,
};

module.exports = {
development: {
username: process.env.DB_DEV_USER,
password: process.env.DB_DEV_PASS,
database: process.env.DB_DEV_DB,
host: process.env.DB_DEV_HOST,
seederStorage: 'json',
dialect: 'mysql',
migrationStorageTableName: 'migrations',
operatorsAliases: false,
pool: pool,
define: define,
},
test: {
username: process.env.DB_TEST_USER,
password: process.env.DB_TEST_PASS,
database: process.env.DB_TEST_DB,
host: process.env.DB_TEST_HOST,
seederStorage: 'json',
dialect: 'mysql',
migrationStorageTableName: 'migrations',
operatorsAliases: false,
pool: pool,
define: define,
},
production: {
username: process.env.DB_PROD_USER,
password: process.env.DB_PROD_PASS,
database: process.env.DB_PROD_DB,
host: process.env.DB_PROD_HOST,
seederStorage: 'json',
dialect: 'mysql',
migrationStorageTableName: 'migrations',
operatorsAliases: false,
pool: pool,
define: define,
},
};
19 changes: 19 additions & 0 deletions db/migrations/20181220105734-create-api-scopes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Api__Scopes', {
name: {
primaryKey: true,
type: Sequelize.STRING,
comment: 'Nom du scope',
},
description: {
type: Sequelize.STRING,
comment: 'Description du scope',
},
});
},
down: queryInterface => {
return queryInterface.dropTable('Api__Scopes');
},
};
32 changes: 32 additions & 0 deletions db/migrations/20181220110500-create-api-token-aliases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Api__TokenAliases', {
token: {
allowNull: false,
primaryKey: true,
type: Sequelize.STRING,
comment: 'Token',
},
alias: {
allowNull: false,
primaryKey: true,
type: Sequelize.STRING,
comment: 'Alias du groupe de scopes',
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
comment: 'Creation date',
},
updatedAt: {
allowNull: true,
type: Sequelize.DATE,
comment: 'Update date',
},
});
},
down: queryInterface => {
return queryInterface.dropTable('Api__TokenAliases');
},
};
30 changes: 30 additions & 0 deletions db/migrations/20181220110530-create-api-token-expirations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Api__TokenExpirations', {
token: {
allowNull: false,
primaryKey: true,
type: Sequelize.STRING,
comment: 'Token',
},
expires: {
type: Sequelize.DATE,
comment: 'Expiration du token',
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
comment: 'Creation date',
},
updatedAt: {
allowNull: true,
type: Sequelize.DATE,
comment: 'Update date',
},
});
},
down: queryInterface => {
return queryInterface.dropTable('Api__TokenExpirations');
},
};
33 changes: 33 additions & 0 deletions db/migrations/20181220110608-create-api-token-scopes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Api__TokenScopes', {
name: {
type: Sequelize.STRING,
primaryKey: true,
allowNull: false,
comment: 'Nom du scope',
references: { model: 'Api__Scopes', key: 'name' },
},
groupName: {
primaryKey: true,
allowNull: false,
type: Sequelize.STRING,
comment: 'Nom du groupe de scopes',
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
comment: 'Creation date',
},
updatedAt: {
allowNull: true,
type: Sequelize.DATE,
comment: 'Update date',
},
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Api__TokenScopes');
},
};
18 changes: 18 additions & 0 deletions db/migrations/20190121093152-create-api-function-tokenExists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

module.exports = {
up: (queryInterface, Sequelize) => {
// SET GLOBAL log_bin_trust_function_creators = 1;
return queryInterface.sequelize.query(
`CREATE FUNCTION \`tokenExists\`(\`token\` VARCHAR(128) CHARSET utf8mb4)
RETURNS tinyint(1) unsigned READS SQL DATA
BEGIN
RETURN ( SELECT Count(*) FROM Api__TokenAliases WHERE Api__TokenAliases.token = token ) > 0;
END`
);
},

down: (queryInterface, Sequelize) => {
return queryInterface.sequelize.query('DROP FUNCTION tokenExists');
},
};
18 changes: 18 additions & 0 deletions db/migrations/20190121093528-create-api-function-hasPermission.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

module.exports = {
up: (queryInterface, Sequelize) => {
// SET GLOBAL log_bin_trust_function_creators = 1;
return queryInterface.sequelize.query(
`CREATE FUNCTION \`hasPermission\`(\`token\` VARCHAR(128) CHARSET utf8mb4, \`scope\` VARCHAR(50)CHARSET utf8mb4)
RETURNS tinyint(1) READS SQL DATA
BEGIN
RETURN ( SELECT COUNT(*) > 0 FROM Api__TokenAliases,Api__TokenScopes WHERE Api__TokenAliases.alias = Api__TokenScopes.groupName AND Api__TokenAliases.token = token AND Api__TokenScopes.name = scope);
END`
);
},

down: (queryInterface, Sequelize) => {
return queryInterface.sequelize.query('DROP FUNCTION hasPermission');
},
};
27 changes: 27 additions & 0 deletions db/migrations/20190121114759-data-public-token-alias.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

module.exports = {
up: (queryInterface, Sequelize) => {
const Api__TokenAliases = queryInterface.sequelize.import(
__dirname + '/../models/api__tokenaliases'
);
return Api__TokenAliases.create({
token: 'PuBlIcWGESsra7tbxYsDQ8PQOhMT0KeN',
alias: 'public',
});
},

down: (queryInterface, Sequelize) => {
const Api__TokenAliases = queryInterface.sequelize.import(
__dirname + '/../models/api__tokenaliases'
);
return Api__TokenAliases.findOne({
where: {
token: 'PuBlIcWGESsra7tbxYsDQ8PQOhMT0KeN',
alias: 'public',
},
}).then(model => {
model.destroy();
});
},
};
22 changes: 22 additions & 0 deletions db/migrations/20190121120428-data-public-api-scopes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

module.exports = {
up: (queryInterface, Sequelize) => {
const Api__Scopes = queryInterface.sequelize.import(
__dirname + '/../models/api__scopes'
);
return Api__Scopes.create({
name: 'api.index',
description: 'Api description and status',
});
},

down: (queryInterface, Sequelize) => {
const Api__Scopes = queryInterface.sequelize.import(
__dirname + '/../models/api__scopes'
);
return Api__Scopes.findByPk('api.index').then(model => {
model.destroy();
});
},
};
27 changes: 27 additions & 0 deletions db/migrations/20190121122225-data-public-api-token-scopes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

module.exports = {
up: (queryInterface, Sequelize) => {
const Api__TokenScopes = queryInterface.sequelize.import(
__dirname + '/../models/api__tokenscopes'
);
return Api__TokenScopes.create({
name: 'api.index',
groupName: 'public',
});
},

down: (queryInterface, Sequelize) => {
const Api__TokenScopes = queryInterface.sequelize.import(
__dirname + '/../models/api__tokenscopes'
);
return Api__TokenScopes.findOne({
where: {
name: 'api.index',
groupName: 'public',
},
}).then(model => {
model.destroy();
});
},
};
Loading

0 comments on commit 18ea9e4

Please sign in to comment.