From 3f90e3a0ef64f6ee470c4d6db9bf61000c5d57ae Mon Sep 17 00:00:00 2001 From: Nung Pothi Date: Mon, 11 Jul 2016 18:23:50 +0700 Subject: [PATCH] เรียงลำดับการทำงานเป็นส่วนๆ --- .gitignore | 337 ++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- common/models/callback.js | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/callback.json | 13 +++++++++++++ common/models/config.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/config.json | 13 +++++++++++++ common/models/files.js | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/files.json | 13 +++++++++++++ common/models/item.js | 7 +++++-- common/models/logs.js | 15 +++++++++++++++ common/models/logs.json | 13 +++++++++++++ common/models/moment.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/moment.json | 13 +++++++++++++ common/models/promises.js | 26 ++++++++++++++++++++++++++ common/models/promises.json | 13 +++++++++++++ common/models/unirest.js | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/unirest.json | 13 +++++++++++++ common/models/uploads.txt | 3 +++ common/uploads/upload.txt | 6 ++++++ config/config.yml | 5 +++++ package.json | 3 +++ server/boot/myapp.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ server/config.json | 2 +- server/datasources.json | 81 --------------------------------------------------------------------------------- server/model-config.json | 28 ++++++++++++++++++++++++++++ 24 files changed, 598 insertions(+), 407 deletions(-) create mode 100644 common/models/callback.js create mode 100644 common/models/callback.json create mode 100644 common/models/config.js create mode 100644 common/models/config.json create mode 100644 common/models/files.js create mode 100644 common/models/files.json create mode 100644 common/models/logs.js create mode 100644 common/models/logs.json create mode 100644 common/models/moment.js create mode 100644 common/models/moment.json create mode 100644 common/models/promises.js create mode 100644 common/models/promises.json create mode 100644 common/models/unirest.js create mode 100644 common/models/unirest.json create mode 100644 common/models/uploads.txt create mode 100644 common/uploads/upload.txt create mode 100644 config/config.yml create mode 100644 server/boot/myapp.js diff --git a/.gitignore b/.gitignore index 5db77b2..aff1045 100644 --- a/.gitignore +++ b/.gitignore @@ -1,328 +1,19 @@ - -# Created by https://www.gitignore.io/api/jetbrains,eclipse,node,composer,java,windows,osx,linux,bower,grunt,netbeans,android,laravel - -### OSX ### -*.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - - -### JetBrains ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# All idea folder -.idea/* - -# User-specific stuff: -.idea/workspace.xml -.idea/tasks.xml -.idea/dictionaries -.idea/vcs.xml -.idea/jsLibraryMappings.xml - -# Sensitive or high-churn files: -.idea/dataSources.ids -.idea/dataSources.xml -.idea/dataSources.local.xml -.idea/sqlDataSources.xml -.idea/dynamic.xml -.idea/uiDesigner.xml - -# Gradle: -.idea/gradle.xml -.idea/libraries - -# Mongo Explorer plugin: -.idea/mongoSettings.xml - -## File-based project format: -*.iws - -## Plugin-specific files: - -# IntelliJ -/out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -### JetBrains Patch ### -# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 - -# *.iml -# modules.xml - - -### Node ### -# Logs -logs +*.csv +*.dat +*.iml *.log -npm-debug.log* - -# Runtime data -pids +*.out *.pid *.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules -jspm_packages - -# Optional npm cache directory -.npm - -# Optional REPL history -.node_repl_history - - -### Composer ### -composer.phar -/vendor/ - -# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file -# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file -# composer.lock - - -### Android ### -# Built application files -*.apk -*.ap_ - -# Files for the ART/Dalvik VM -*.dex - -# Java class files -*.class - -# Generated files -bin/ -gen/ -out/ - -# Gradle files -.gradle/ -build/ - -# Local configuration file (sdk path, etc) -local.properties - -# Proguard folder generated by Eclipse -proguard/ - -# Log Files -*.log - -# Android Studio Navigation editor temp files -.navigation/ - -# Android Studio captures folder -captures/ - -# Intellij -*.iml -.idea/workspace.xml - -# Keystore files -*.jks - -### Android Patch ### -gen-external-apklibs - - -### Windows ### -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msm -*.msp - -# Windows shortcuts -*.lnk - - -### Eclipse ### - -.metadata -bin/ -tmp/ -*.tmp -*.bak +*.sublime-* +*.swo *.swp -*~.nib -local.properties -.settings/ -.loadpath -.recommenders - -# Eclipse Core +*.tgz +*.xml +.DS_Store +.idea .project - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# PyDev specific (Python IDE for Eclipse) -*.pydevproject - -# CDT-specific (C/C++ Development Tooling) -.cproject - -# JDT-specific (Eclipse Java Development Tools) -.classpath - -# Java annotation processor (APT) -.factorypath - -# PDT-specific (PHP Development Tools) -.buildpath - -# sbteclipse plugin -.target - -# Tern plugin -.tern-project - -# TeXlipse plugin -.texlipse - -# STS (Spring Tool Suite) -.springBeans - -# Code Recommenders -.recommenders/ - - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - - -### Bower ### -bower_components -.bower-cache -.bower-registry -.bower-tmp - - -### grunt ### -# Grunt usually compiles files inside this directory -dist/ - -# Grunt usually preprocesses files such as coffeescript, compass... inside the .tmp directory -.tmp/ - - -### NetBeans ### -nbproject/private/ -build/ -nbbuild/ -dist/ -nbdist/ -nbactions.xml -.nb-gradle/ - - -### Laravel ### -vendor/ -node_modules/ - -# Laravel 4 specific -bootstrap/compiled.php -app/storage/ - -# Laravel 5 & Lumen specific -bootstrap/cache/ -.env.*.php -.env.php -.env - -# Rocketeer PHP task runner and deployment package. https://github.com/rocketeers/rocketeer -.rocketeer/ - - -### Java ### -*.class - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.ear - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -T6/~$T6_SSB-WO_FirstActivate(SQA)_v1.0.0_24062016.xlsx +.strong-pm +coverage +node_modules +npm-debug.log diff --git a/common/models/callback.js b/common/models/callback.js new file mode 100644 index 0000000..8a4c79b --- /dev/null +++ b/common/models/callback.js @@ -0,0 +1,99 @@ +module.exports = function(Callback) { + Callback.disableRemoteMethod("create", true); + Callback.disableRemoteMethod("upsert", true); + Callback.disableRemoteMethod("updateAll", true); + Callback.disableRemoteMethod("updateAttributes", false); + + Callback.disableRemoteMethod("find", true); + Callback.disableRemoteMethod("findById", true); + Callback.disableRemoteMethod("findOne", true); + + Callback.disableRemoteMethod("deleteById", true); + + Callback.disableRemoteMethod("confirm", true); + Callback.disableRemoteMethod("count", true); + Callback.disableRemoteMethod("exists", true); + Callback.disableRemoteMethod("resetPassword", true); + + Callback.disableRemoteMethod('__count__accessTokens', false); + Callback.disableRemoteMethod('__create__accessTokens', false); + Callback.disableRemoteMethod('__delete__accessTokens', false); + Callback.disableRemoteMethod('__destroyById__accessTokens', false); + Callback.disableRemoteMethod('__findById__accessTokens', false); + Callback.disableRemoteMethod('__get__accessTokens', false); + Callback.disableRemoteMethod('__updateById__accessTokens', false); + + Callback.disableRemoteMethod('create', true); // Removes (POST) /products + Callback.disableRemoteMethod('upsert', true); // Removes (PUT) /products + Callback.disableRemoteMethod('deleteById', true); // Removes (DELETE) /products/:id + Callback.disableRemoteMethod("updateAll", true); // Removes (POST) /products/update + Callback.disableRemoteMethod("updateAttributes", false); // Removes (PUT) /products/:id + Callback.disableRemoteMethod('createChangeStream', true); // removes (GET|POST) /products/change-stream + + Callback.EmptryParams = function (cb) { + // cb = callback; + var success = { + "resultCode": 20000, + "resultDescription":"Success" + }; + cb(null,success); + }; + Callback.remoteMethod('EmptryParams',{ + http:{path:'/EmptryParams',verb:'get'}, + returns: {arg: 'data', type: 'object', root: true} + }); + Callback.HttpPost = function (ctx,cb) { + // cb = callback; + var success = { + "resultCode": 20000, + "resultDescription":"Success", + "data":ctx + }; + cb(null,success); + }; + Callback.remoteMethod('HttpPost',{ + http:{path:'/HttpPost',verb:'post'}, + accepts: { arg: 'ctx', type: 'object', default: { + "string": "string", + "number": 12345, + "array": ['string',1234], + "object": { + "string":"string", + "number":1234 + } + },http: { source: 'body' }}, + returns: {arg: 'data', type: 'object', root: true} + }); + Callback.HttpGet = function (ctx,cb) { + // cb = callback; + + var success = { + "resultCode": 20000, + "resultDescription":"Success", + "Try it on":"http://localhost:3232/api/callbacks/models1/5555/models2/6666", + "data":ctx + + }; + cb(null,success); + }; + Callback.remoteMethod('HttpGet',{ + http:{path:'/models1/:params1/models2/:params2',verb:'get'}, + accepts: { arg: 'ctx', type: 'object', http: function(ctx) { + // รับข้อมุลมาใส่ไว้ใน ctx + // 1. รับข้อมูล object ที่ส่งมาโดยใช้ express + var req = ctx.req; + + /* 2. Get ข้อมูลแบบ params + * params คือค่าที่ส่งมากับ url ex http://localhost/Item/params1/params2 + * รับค่ามาตั้งแต่ http:{path:'/: ตัวแปรที่รับค่าเก็บไว้ /: ตัวแปรที่รับค่าเก็บไว้ + + */ + var params = { + "params1":req.params.params1, + "params2":req.params.params2 + }; + return params; + } } , + returns: {arg: 'data', type: 'object', root: true} + }); +}; diff --git a/common/models/callback.json b/common/models/callback.json new file mode 100644 index 0000000..c1149dd --- /dev/null +++ b/common/models/callback.json @@ -0,0 +1,13 @@ +{ + "name": "callback", + "base": "PersistedModel", + "idInjection": true, + "options": { + "validateUpsert": true + }, + "properties": {}, + "validations": [], + "relations": {}, + "acls": [], + "methods": {} +} diff --git a/common/models/config.js b/common/models/config.js new file mode 100644 index 0000000..7bf52c1 --- /dev/null +++ b/common/models/config.js @@ -0,0 +1,50 @@ + +var yaml = require('node-yaml-config'); +var config = yaml.load(__dirname + '/../../config/config.yml'); +module.exports = function(Config) { + + + Config.disableRemoteMethod("create", true); + Config.disableRemoteMethod("upsert", true); + Config.disableRemoteMethod("updateAll", true); + Config.disableRemoteMethod("updateAttributes", false); + + Config.disableRemoteMethod("find", true); + Config.disableRemoteMethod("findById", true); + Config.disableRemoteMethod("findOne", true); + + Config.disableRemoteMethod("deleteById", true); + + Config.disableRemoteMethod("confirm", true); + Config.disableRemoteMethod("count", true); + Config.disableRemoteMethod("exists", true); + Config.disableRemoteMethod("resetPassword", true); + + Config.disableRemoteMethod('__count__accessTokens', false); + Config.disableRemoteMethod('__create__accessTokens', false); + Config.disableRemoteMethod('__delete__accessTokens', false); + Config.disableRemoteMethod('__destroyById__accessTokens', false); + Config.disableRemoteMethod('__findById__accessTokens', false); + Config.disableRemoteMethod('__get__accessTokens', false); + Config.disableRemoteMethod('__updateById__accessTokens', false); + + Config.disableRemoteMethod('create', true); // Removes (POST) /products + Config.disableRemoteMethod('upsert', true); // Removes (PUT) /products + Config.disableRemoteMethod('deleteById', true); // Removes (DELETE) /products/:id + Config.disableRemoteMethod("updateAll", true); // Removes (POST) /products/update + Config.disableRemoteMethod("updateAttributes", false); // Removes (PUT) /products/:id + Config.disableRemoteMethod('createChangeStream', true); // removes (GET|POST) /products/change-stream + + Config.HttpGet = function (cb) { + var success = { + "config":config.server.config, + "docs":config.server.docs, + "directory":config.server.directory + }; + cb(null,success); + }; + Config.remoteMethod('HttpGet',{ + http:{path:'/config',verb:'get'}, + returns: {arg: 'data', type: 'object', root: true} + }); +}; diff --git a/common/models/config.json b/common/models/config.json new file mode 100644 index 0000000..87a4e9c --- /dev/null +++ b/common/models/config.json @@ -0,0 +1,13 @@ +{ + "name": "config", + "base": "PersistedModel", + "idInjection": true, + "options": { + "validateUpsert": true + }, + "properties": {}, + "validations": [], + "relations": {}, + "acls": [], + "methods": {} +} diff --git a/common/models/files.js b/common/models/files.js new file mode 100644 index 0000000..0310efe --- /dev/null +++ b/common/models/files.js @@ -0,0 +1,70 @@ +var fs_ex = require('fs.extra'); +var fs = require('fs'); +var console = process.console; +module.exports = function(Files) { + + Files.disableRemoteMethod("create", true); + Files.disableRemoteMethod("upsert", true); + Files.disableRemoteMethod("updateAll", true); + Files.disableRemoteMethod("updateAttributes", false); + + Files.disableRemoteMethod("find", true); + Files.disableRemoteMethod("findById", true); + Files.disableRemoteMethod("findOne", true); + + Files.disableRemoteMethod("deleteById", true); + + Files.disableRemoteMethod("confirm", true); + Files.disableRemoteMethod("count", true); + Files.disableRemoteMethod("exists", true); + Files.disableRemoteMethod("resetPassword", true); + + Files.disableRemoteMethod('__count__accessTokens', false); + Files.disableRemoteMethod('__create__accessTokens', false); + Files.disableRemoteMethod('__delete__accessTokens', false); + Files.disableRemoteMethod('__destroyById__accessTokens', false); + Files.disableRemoteMethod('__findById__accessTokens', false); + Files.disableRemoteMethod('__get__accessTokens', false); + Files.disableRemoteMethod('__updateById__accessTokens', false); + + Files.disableRemoteMethod('create', true); // Removes (POST) /products + Files.disableRemoteMethod('upsert', true); // Removes (PUT) /products + Files.disableRemoteMethod('deleteById', true); // Removes (DELETE) /products/:id + Files.disableRemoteMethod("updateAll", true); // Removes (POST) /products/update + Files.disableRemoteMethod("updateAttributes", false); // Removes (PUT) /products/:id + Files.disableRemoteMethod('createChangeStream', true); // removes (GET|POST) /products/change-stream + + + Files.Files = function(ctx,cb){ + var path = __dirname+'/../uploads/upload'; + console.log(path); + fs.readFile(path+'.txt', 'utf8', function (err, body) { + if (err){ + FnwriteFile(body,ctx) + }else{ + FnwriteFile(body,ctx) + } + }); + }; + function FnwriteFile(body,data){ + var path = __dirname+'/../uploads/upload'; + + //Do your processing, MD5, send a satellite to the moon, etc. + fs.writeFile(path+'.txt', body+"\n"+data.data, 'utf8', function (err) { + if (err) { + console.log(err); + }else { + console.tag('docs').log("Write file complete"); + } + }); + + } + Files.remoteMethod('Files',{ + http:{path:'/Files',verb:'post'}, + accepts: { arg: 'ctx', type: 'object', default: { + "data":"https://www.npmjs.com/package/fs.extra // https://nodejs.org/api/fs.html" + },http: { source: 'body' }}, + returns: {arg: 'data', type: 'object', root: true} + }) + +}; diff --git a/common/models/files.json b/common/models/files.json new file mode 100644 index 0000000..1674633 --- /dev/null +++ b/common/models/files.json @@ -0,0 +1,13 @@ +{ + "name": "files", + "base": "PersistedModel", + "idInjection": true, + "options": { + "validateUpsert": true + }, + "properties": {}, + "validations": [], + "relations": {}, + "acls": [], + "methods": {} +} diff --git a/common/models/item.js b/common/models/item.js index 03fdbbd..2afb40d 100644 --- a/common/models/item.js +++ b/common/models/item.js @@ -100,8 +100,11 @@ module.exports = function(Item) { Item.Moment = function(cb){ var this_time = { "default": moment().format(), - "DD-MM-YYY":moment().format("DD-MM-YYYY"), - "HH:MM:SS":moment().format("HH:mm:ss") + "DD-MM-YYYY":moment().format("DD-MM-YYYY"), + "HH:MM:SS":moment().format("HH:mm:ss"), + "DDMMYYYY":moment().format("DDMMYYYY"), + "DD-MM-YYYY HH:II::SS":moment().format("DD-MM-YYYY HH:mm:ss"), + "YYYYMMDD-HHmmssSSS":moment().format("YYYYMMDD-HHmmssSSS") }; cb(null,this_time); }; diff --git a/common/models/logs.js b/common/models/logs.js new file mode 100644 index 0000000..19dcdde --- /dev/null +++ b/common/models/logs.js @@ -0,0 +1,15 @@ +var console = process.console; +module.exports = function(Logs) { + Logs.Logs = function(cb){ + console.tag('TestLog','Logs').file().time().log('http://localhost:3232/logs/'); + console.tag('TestLog','Logs').file().time().warning('http://localhost:3232/logs/'); + console.tag('TestLog','Logs').file().time().error('http://localhost:3232/logs/'); + console.tag('TestLog','Logs').file().time().info('http://localhost:3232/logs/'); + cb(null); + }; + Logs.remoteMethod('Logs',{ + http:{path:'/Logs',verb:'get'}, + returns: {arg: 'data', type: 'object', root: true} + }); + +}; diff --git a/common/models/logs.json b/common/models/logs.json new file mode 100644 index 0000000..5935d14 --- /dev/null +++ b/common/models/logs.json @@ -0,0 +1,13 @@ +{ + "name": "logs", + "base": "PersistedModel", + "idInjection": true, + "options": { + "validateUpsert": true + }, + "properties": {}, + "validations": [], + "relations": {}, + "acls": [], + "methods": {} +} diff --git a/common/models/moment.js b/common/models/moment.js new file mode 100644 index 0000000..e342de8 --- /dev/null +++ b/common/models/moment.js @@ -0,0 +1,55 @@ + +var moment = require('moment'); +module.exports = function(Moment) { + + Moment.disableRemoteMethod("create", true); + Moment.disableRemoteMethod("upsert", true); + Moment.disableRemoteMethod("updateAll", true); + Moment.disableRemoteMethod("updateAttributes", false); + + Moment.disableRemoteMethod("find", true); + Moment.disableRemoteMethod("findById", true); + Moment.disableRemoteMethod("findOne", true); + + Moment.disableRemoteMethod("deleteById", true); + + Moment.disableRemoteMethod("confirm", true); + Moment.disableRemoteMethod("count", true); + Moment.disableRemoteMethod("exists", true); + Moment.disableRemoteMethod("resetPassword", true); + + Moment.disableRemoteMethod('__count__accessTokens', false); + Moment.disableRemoteMethod('__create__accessTokens', false); + Moment.disableRemoteMethod('__delete__accessTokens', false); + Moment.disableRemoteMethod('__destroyById__accessTokens', false); + Moment.disableRemoteMethod('__findById__accessTokens', false); + Moment.disableRemoteMethod('__get__accessTokens', false); + Moment.disableRemoteMethod('__updateById__accessTokens', false); + + Moment.disableRemoteMethod('create', true); // Removes (POST) /products + Moment.disableRemoteMethod('upsert', true); // Removes (PUT) /products + Moment.disableRemoteMethod('deleteById', true); // Removes (DELETE) /products/:id + Moment.disableRemoteMethod("updateAll", true); // Removes (POST) /products/update + Moment.disableRemoteMethod("updateAttributes", false); // Removes (PUT) /products/:id + Moment.disableRemoteMethod('createChangeStream', true); // removes (GET|POST) /products/change-stream + + + Moment.Moment = function(cb){ + var this_time = { + "docs":"http://momentjs.com/docs/", + "default": moment().format(), + "DD-MM-YYYY":moment().format("DD-MM-YYYY"), + "HH:MM:SS":moment().format("HH:mm:ss"), + "DDMMYYYY":moment().format("DDMMYYYY"), + "DD-MM-YYYY HH:II::SS":moment().format("DD-MM-YYYY HH:mm:ss"), + "YYYYMMDD-HHmmssSSS":moment().format("YYYYMMDD-HHmmssSSS") + }; + cb(null,this_time); + + }; + Moment.remoteMethod('Moment',{ + http:{path:'/Moment',verb:'get'}, + returns: {arg: 'data', type: 'object', root: true} + }) + +}; diff --git a/common/models/moment.json b/common/models/moment.json new file mode 100644 index 0000000..fa92358 --- /dev/null +++ b/common/models/moment.json @@ -0,0 +1,13 @@ +{ + "name": "moment", + "base": "PersistedModel", + "idInjection": true, + "options": { + "validateUpsert": true + }, + "properties": {}, + "validations": [], + "relations": {}, + "acls": [], + "methods": {} +} diff --git a/common/models/promises.js b/common/models/promises.js new file mode 100644 index 0000000..6527782 --- /dev/null +++ b/common/models/promises.js @@ -0,0 +1,26 @@ +var bluebird = require('bluebird'); +var promise = new Promise(function (resolve,reject) { + resolve('success') +}) +module.exports = function(Promises) { + Promises.Ex = function (cb) { + promise + .then(MyFunc1()) + .then(MyFunc2()); + + }; + function MyFunc1(){ + setTimeout(function(){ + console.log('first'); + return true; + },1000); + } + function MyFunc2(){ + console.log('second'); + } + Promises.remoteMethod('Ex',{ + http:{path:'/Ex',verb:'get'}, + accepts: { arg: 'ctx', type: 'object' } , + returns: {arg: 'data', type: 'object', root: true} + }) +}; diff --git a/common/models/promises.json b/common/models/promises.json new file mode 100644 index 0000000..a1ac92d --- /dev/null +++ b/common/models/promises.json @@ -0,0 +1,13 @@ +{ + "name": "promises", + "base": "PersistedModel", + "idInjection": true, + "options": { + "validateUpsert": true + }, + "properties": {}, + "validations": [], + "relations": {}, + "acls": [], + "methods": {} +} diff --git a/common/models/unirest.js b/common/models/unirest.js new file mode 100644 index 0000000..44bf3d5 --- /dev/null +++ b/common/models/unirest.js @@ -0,0 +1,82 @@ +var console = process.console; +var unirest = require('unirest'); + +module.exports = function(Unirest) { + + Unirest.disableRemoteMethod("create", true); + Unirest.disableRemoteMethod("upsert", true); + Unirest.disableRemoteMethod("updateAll", true); + Unirest.disableRemoteMethod("updateAttributes", false); + + Unirest.disableRemoteMethod("find", true); + Unirest.disableRemoteMethod("findById", true); + Unirest.disableRemoteMethod("findOne", true); + + Unirest.disableRemoteMethod("deleteById", true); + + Unirest.disableRemoteMethod("confirm", true); + Unirest.disableRemoteMethod("count", true); + Unirest.disableRemoteMethod("exists", true); + Unirest.disableRemoteMethod("resetPassword", true); + + Unirest.disableRemoteMethod('__count__accessTokens', false); + Unirest.disableRemoteMethod('__create__accessTokens', false); + Unirest.disableRemoteMethod('__delete__accessTokens', false); + Unirest.disableRemoteMethod('__destroyById__accessTokens', false); + Unirest.disableRemoteMethod('__findById__accessTokens', false); + Unirest.disableRemoteMethod('__get__accessTokens', false); + Unirest.disableRemoteMethod('__updateById__accessTokens', false); + + Unirest.disableRemoteMethod('create', true); // Removes (POST) /products + Unirest.disableRemoteMethod('upsert', true); // Removes (PUT) /products + Unirest.disableRemoteMethod('deleteById', true); // Removes (DELETE) /products/:id + Unirest.disableRemoteMethod("updateAll", true); // Removes (POST) /products/update + Unirest.disableRemoteMethod("updateAttributes", false); // Removes (PUT) /products/:id + Unirest.disableRemoteMethod('createChangeStream', true); // removes (GET|POST) /products/change-stream + + + Unirest.HttpPost = function (ctx,cb) { + console.log(ctx); + var success = { + "resultCode": 20000, + "resultDescription":"Success", + "data":ctx + }; + console.log(success); + cb(null,success); + }; + Unirest.remoteMethod('HttpPost',{ + http:{path:'/HttpPost',verb:'post'}, + accepts: { arg: 'ctx', type: 'object',http: { source: 'body' }}, + returns: {arg: 'data', type: 'object', root: true} + }); + Unirest.HttpGet = function (ctx,cb) { + // cb = callback; + var data = { + "data":ctx + }; + unirest.post('http://localhost:3232/api/unirests/HttpPost') + .send(data) + .end(function (response) { + response.body.data.docs = "http://unirest.io/nodejs.html"; + console.log(response.body); + cb(null,response.body) + }); + }; + Unirest.remoteMethod('HttpGet',{ + http:{path:'/unirest/:data',verb:'get'}, + accepts: { arg: 'ctx', type: 'string', http: function(ctx) { + // รับข้อมุลมาใส่ไว้ใน ctx + // 1. รับข้อมูล object ที่ส่งมาโดยใช้ express + var req = ctx.req; + + /* 2. Get ข้อมูลแบบ params + * params คือค่าที่ส่งมากับ url ex http://localhost/Item/params1/params2 + * รับค่ามาตั้งแต่ http:{path:'/: ตัวแปรที่รับค่าเก็บไว้ /: ตัวแปรที่รับค่าเก็บไว้ + + */ + return req.params.data; + } } , + returns: {arg: 'data', type: 'object', root: true} + }); +}; diff --git a/common/models/unirest.json b/common/models/unirest.json new file mode 100644 index 0000000..a7cac50 --- /dev/null +++ b/common/models/unirest.json @@ -0,0 +1,13 @@ +{ + "name": "unirest", + "base": "PersistedModel", + "idInjection": true, + "options": { + "validateUpsert": true + }, + "properties": {}, + "validations": [], + "relations": {}, + "acls": [], + "methods": {} +} diff --git a/common/models/uploads.txt b/common/models/uploads.txt new file mode 100644 index 0000000..b2a6438 --- /dev/null +++ b/common/models/uploads.txt @@ -0,0 +1,3 @@ +undefined +string +string \ No newline at end of file diff --git a/common/uploads/upload.txt b/common/uploads/upload.txt new file mode 100644 index 0000000..d0f7871 --- /dev/null +++ b/common/uploads/upload.txt @@ -0,0 +1,6 @@ +undefined +string +string +string +https://www.npmjs.com/package/fs.extra // https://nodejs.org/api/fs.html +https://www.npmjs.com/package/fs.extra // https://nodejs.org/api/fs.html \ No newline at end of file diff --git a/config/config.yml b/config/config.yml new file mode 100644 index 0000000..d139c31 --- /dev/null +++ b/config/config.yml @@ -0,0 +1,5 @@ +developer: + server: + config: 'Edit here' + docs: 'https://cloud.google.com/appengine/docs/flexible/nodejs/configuring-your-app-with-app-yaml' + directory : 'config/config.yml' \ No newline at end of file diff --git a/package.json b/package.json index e5b9606..7a8172c 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,12 @@ "posttest": "nsp check" }, "dependencies": { + "bluebird": "^3.4.1", "body-parser": "^1.15.2", "compression": "^1.0.3", "cors": "^2.5.2", "ejs": "^2.4.2", + "fs.extra": "^1.3.2", "helmet": "^1.3.0", "loopback": "^2.22.0", "loopback-boot": "^2.6.5", @@ -20,6 +22,7 @@ "loopback-connector-mysql": "^2.3.0", "loopback-datasource-juggler": "^2.39.0", "moment": "^2.13.0", + "node-yaml-config": "0.0.4", "path": "^0.12.7", "scribe-js": "^2.0.4", "serve-favicon": "^2.0.1", diff --git a/server/boot/myapp.js b/server/boot/myapp.js new file mode 100644 index 0000000..3d704e1 --- /dev/null +++ b/server/boot/myapp.js @@ -0,0 +1,45 @@ +/** + * Created by Develop-SC on 11/7/2559. + */ +module.exports = function(app) { + + function modifyResponse(ctx, model, next) { + var response; + var status = ctx.res.statusCode; + console.log(status); + console.log(model); + if(status === 200){ + response = { + "resultCode":model.resultCode ? model.resultCode : "20000", + "resultDescript": model.resultDescript ? model.resultDescript : "Success", + "data": model.data ? model.data : model + }; + }else{ + response = { + "resultCode":model.resultCode ? model.resultCode : "20000", + "resultDescript": model.resultDescript ? model.resultDescript : "Success", + "data": model.data ? model.data : model + }; + + } + ctx.res.send(response) + .end(); + } + function modifyError(ctx,model,next){ + var fail = { + "resultCode": 50000, + "resultDescription":"fail" + }; + ctx.res.send(fail).end(); + } + /*function validate(ctx,model,next){ + var fail = { + "resultCode": 50000, + "resultDescription":"fail" + }; + ctx.res.send(fail).end(); + } + app.models.beforeRemote('**', validate);*/ + app.models.Logs.afterRemote('**', modifyResponse); + app.models.Logs.afterRemoteError('**', modifyError); +}; \ No newline at end of file diff --git a/server/config.json b/server/config.json index ac5e58c..d08ed21 100644 --- a/server/config.json +++ b/server/config.json @@ -1,7 +1,7 @@ { "restApiRoot": "/api", "host": "0.0.0.0", - "port": 3000, + "port": 3232, "remoting": { "context": { "enableHttpContext": false diff --git a/server/datasources.json b/server/datasources.json index 08b36a8..9063014 100644 --- a/server/datasources.json +++ b/server/datasources.json @@ -22,86 +22,5 @@ "name": "radius", "user": "radius", "connector": "mysql" - }, - "account": { - "host": "server8.sourcecode.co.th", - "port": 3306, - "url": "", - "database": "account", - "password": "A83kKhoAH4jcEHMY", - "name": "account", - "user": "npm_account", - "connector": "mysql" - }, - "refill": { - "host": "server8.sourcecode.co.th", - "port": 3306, - "url": "", - "database": "refill", - "password": "Fe8Vf63LtdGQaFtd", - "name": "refill", - "user": "npm_refill", - "connector": "mysql" - }, - "smartquotation": { - "host": "server8.sourcecode.co.th", - "port": 3306, - "url": "", - "database": "smartquotation", - "password": "Bwa7Z6ZRosU4RuAH", - "name": "smartquotation", - "user": "npm_smtquot", - "connector": "mysql" - }, - "smartzone": { - "host": "server8.sourcecode.co.th", - "port": 3306, - "url": "", - "database": "smartzone", - "password": "pADobokFAoPC384B", - "name": "account", - "user": "npm_szv3", - "connector": "mysql" - }, - "smartzonev4": { - "host": "server8.sourcecode.co.th", - "port": 3306, - "url": "", - "database": "smartzonev4", - "password": "Q7TsWo7UNbCsi3sb", - "name": "smartzonev4", - "user": "npm_szv4", - "connector": "mysql" - }, - "thespecialdress": { - "host": "server8.sourcecode.co.th", - "port": 3306, - "url": "", - "database": "thespecialdress", - "password": "bXGhkLoTJ9atAx72", - "name": "thespecialdress", - "user": "npm_tsd", - "connector": "mysql" - }, - "thespecialdress_wp": { - "host": "server8.sourcecode.co.th", - "port": 3306, - "url": "", - "database": "thespecialdress_wp", - "password": "gAUmK7Jcvq4F7CUs", - "name": "thespecialdress_wp", - "user": "npm_tsdwp", - "connector": "mysql" - }, - "vtigercrm510": { - "host": "server8.sourcecode.co.th", - "port": 3306, - "url": "", - "database": "vtigercrm510", - "password": "X6UUfWM8GJEPBzv3", - "name": "vtigercrm510", - "user": "npm_vtiger", - "connector": "mysql" } } - diff --git a/server/model-config.json b/server/model-config.json index 48e5d72..bc866cc 100644 --- a/server/model-config.json +++ b/server/model-config.json @@ -43,5 +43,33 @@ "order": { "dataSource": "mongodb", "public": true + }, + "promises": { + "dataSource": "db", + "public": true + }, + "logs": { + "dataSource": "db", + "public": true + }, + "callback": { + "dataSource": "db", + "public": true + }, + "moment": { + "dataSource": "db", + "public": true + }, + "files": { + "dataSource": "db", + "public": true + }, + "unirest": { + "dataSource": "db", + "public": true + }, + "config": { + "dataSource": "db", + "public": true } } -- libgit2 0.21.2