Commit 3f90e3a0ef64f6ee470c4d6db9bf61000c5d57ae

Authored by Nung Poti
1 parent f296ec68
Exists in master

เรียงลำดับการทำงานเป็นส่วนๆ

.gitignore
1   -
2   -# Created by https://www.gitignore.io/api/jetbrains,eclipse,node,composer,java,windows,osx,linux,bower,grunt,netbeans,android,laravel
3   -
4   -### OSX ###
5   -*.DS_Store
6   -.AppleDouble
7   -.LSOverride
8   -
9   -# Icon must end with two \r
10   -Icon
11   -
12   -
13   -# Thumbnails
14   -._*
15   -
16   -# Files that might appear in the root of a volume
17   -.DocumentRevisions-V100
18   -.fseventsd
19   -.Spotlight-V100
20   -.TemporaryItems
21   -.Trashes
22   -.VolumeIcon.icns
23   -.com.apple.timemachine.donotpresent
24   -
25   -# Directories potentially created on remote AFP share
26   -.AppleDB
27   -.AppleDesktop
28   -Network Trash Folder
29   -Temporary Items
30   -.apdisk
31   -
32   -
33   -### JetBrains ###
34   -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
35   -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
36   -
37   -# All idea folder
38   -.idea/*
39   -
40   -# User-specific stuff:
41   -.idea/workspace.xml
42   -.idea/tasks.xml
43   -.idea/dictionaries
44   -.idea/vcs.xml
45   -.idea/jsLibraryMappings.xml
46   -
47   -# Sensitive or high-churn files:
48   -.idea/dataSources.ids
49   -.idea/dataSources.xml
50   -.idea/dataSources.local.xml
51   -.idea/sqlDataSources.xml
52   -.idea/dynamic.xml
53   -.idea/uiDesigner.xml
54   -
55   -# Gradle:
56   -.idea/gradle.xml
57   -.idea/libraries
58   -
59   -# Mongo Explorer plugin:
60   -.idea/mongoSettings.xml
61   -
62   -## File-based project format:
63   -*.iws
64   -
65   -## Plugin-specific files:
66   -
67   -# IntelliJ
68   -/out/
69   -
70   -# mpeltonen/sbt-idea plugin
71   -.idea_modules/
72   -
73   -# JIRA plugin
74   -atlassian-ide-plugin.xml
75   -
76   -# Crashlytics plugin (for Android Studio and IntelliJ)
77   -com_crashlytics_export_strings.xml
78   -crashlytics.properties
79   -crashlytics-build.properties
80   -fabric.properties
81   -
82   -### JetBrains Patch ###
83   -# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
84   -
85   -# *.iml
86   -# modules.xml
87   -
88   -
89   -### Node ###
90   -# Logs
91   -logs
  1 +*.csv
  2 +*.dat
  3 +*.iml
92 4 *.log
93   -npm-debug.log*
94   -
95   -# Runtime data
96   -pids
  5 +*.out
97 6 *.pid
98 7 *.seed
99   -
100   -# Directory for instrumented libs generated by jscoverage/JSCover
101   -lib-cov
102   -
103   -# Coverage directory used by tools like istanbul
104   -coverage
105   -
106   -# nyc test coverage
107   -.nyc_output
108   -
109   -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
110   -.grunt
111   -
112   -# node-waf configuration
113   -.lock-wscript
114   -
115   -# Compiled binary addons (http://nodejs.org/api/addons.html)
116   -build/Release
117   -
118   -# Dependency directories
119   -node_modules
120   -jspm_packages
121   -
122   -# Optional npm cache directory
123   -.npm
124   -
125   -# Optional REPL history
126   -.node_repl_history
127   -
128   -
129   -### Composer ###
130   -composer.phar
131   -/vendor/
132   -
133   -# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
134   -# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
135   -# composer.lock
136   -
137   -
138   -### Android ###
139   -# Built application files
140   -*.apk
141   -*.ap_
142   -
143   -# Files for the ART/Dalvik VM
144   -*.dex
145   -
146   -# Java class files
147   -*.class
148   -
149   -# Generated files
150   -bin/
151   -gen/
152   -out/
153   -
154   -# Gradle files
155   -.gradle/
156   -build/
157   -
158   -# Local configuration file (sdk path, etc)
159   -local.properties
160   -
161   -# Proguard folder generated by Eclipse
162   -proguard/
163   -
164   -# Log Files
165   -*.log
166   -
167   -# Android Studio Navigation editor temp files
168   -.navigation/
169   -
170   -# Android Studio captures folder
171   -captures/
172   -
173   -# Intellij
174   -*.iml
175   -.idea/workspace.xml
176   -
177   -# Keystore files
178   -*.jks
179   -
180   -### Android Patch ###
181   -gen-external-apklibs
182   -
183   -
184   -### Windows ###
185   -# Windows image file caches
186   -Thumbs.db
187   -ehthumbs.db
188   -
189   -# Folder config file
190   -Desktop.ini
191   -
192   -# Recycle Bin used on file shares
193   -$RECYCLE.BIN/
194   -
195   -# Windows Installer files
196   -*.cab
197   -*.msi
198   -*.msm
199   -*.msp
200   -
201   -# Windows shortcuts
202   -*.lnk
203   -
204   -
205   -### Eclipse ###
206   -
207   -.metadata
208   -bin/
209   -tmp/
210   -*.tmp
211   -*.bak
  8 +*.sublime-*
  9 +*.swo
212 10 *.swp
213   -*~.nib
214   -local.properties
215   -.settings/
216   -.loadpath
217   -.recommenders
218   -
219   -# Eclipse Core
  11 +*.tgz
  12 +*.xml
  13 +.DS_Store
  14 +.idea
220 15 .project
221   -
222   -# External tool builders
223   -.externalToolBuilders/
224   -
225   -# Locally stored "Eclipse launch configurations"
226   -*.launch
227   -
228   -# PyDev specific (Python IDE for Eclipse)
229   -*.pydevproject
230   -
231   -# CDT-specific (C/C++ Development Tooling)
232   -.cproject
233   -
234   -# JDT-specific (Eclipse Java Development Tools)
235   -.classpath
236   -
237   -# Java annotation processor (APT)
238   -.factorypath
239   -
240   -# PDT-specific (PHP Development Tools)
241   -.buildpath
242   -
243   -# sbteclipse plugin
244   -.target
245   -
246   -# Tern plugin
247   -.tern-project
248   -
249   -# TeXlipse plugin
250   -.texlipse
251   -
252   -# STS (Spring Tool Suite)
253   -.springBeans
254   -
255   -# Code Recommenders
256   -.recommenders/
257   -
258   -
259   -### Linux ###
260   -*~
261   -
262   -# temporary files which can be created if a process still has a handle open of a deleted file
263   -.fuse_hidden*
264   -
265   -# KDE directory preferences
266   -.directory
267   -
268   -# Linux trash folder which might appear on any partition or disk
269   -.Trash-*
270   -
271   -
272   -### Bower ###
273   -bower_components
274   -.bower-cache
275   -.bower-registry
276   -.bower-tmp
277   -
278   -
279   -### grunt ###
280   -# Grunt usually compiles files inside this directory
281   -dist/
282   -
283   -# Grunt usually preprocesses files such as coffeescript, compass... inside the .tmp directory
284   -.tmp/
285   -
286   -
287   -### NetBeans ###
288   -nbproject/private/
289   -build/
290   -nbbuild/
291   -dist/
292   -nbdist/
293   -nbactions.xml
294   -.nb-gradle/
295   -
296   -
297   -### Laravel ###
298   -vendor/
299   -node_modules/
300   -
301   -# Laravel 4 specific
302   -bootstrap/compiled.php
303   -app/storage/
304   -
305   -# Laravel 5 & Lumen specific
306   -bootstrap/cache/
307   -.env.*.php
308   -.env.php
309   -.env
310   -
311   -# Rocketeer PHP task runner and deployment package. https://github.com/rocketeers/rocketeer
312   -.rocketeer/
313   -
314   -
315   -### Java ###
316   -*.class
317   -
318   -# Mobile Tools for Java (J2ME)
319   -.mtj.tmp/
320   -
321   -# Package Files #
322   -*.jar
323   -*.war
324   -*.ear
325   -
326   -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
327   -hs_err_pid*
328   -T6/~$T6_SSB-WO_FirstActivate(SQA)_v1.0.0_24062016.xlsx
  16 +.strong-pm
  17 +coverage
  18 +node_modules
  19 +npm-debug.log
... ...
common/models/callback.js 0 → 100644
... ... @@ -0,0 +1,99 @@
  1 +module.exports = function(Callback) {
  2 + Callback.disableRemoteMethod("create", true);
  3 + Callback.disableRemoteMethod("upsert", true);
  4 + Callback.disableRemoteMethod("updateAll", true);
  5 + Callback.disableRemoteMethod("updateAttributes", false);
  6 +
  7 + Callback.disableRemoteMethod("find", true);
  8 + Callback.disableRemoteMethod("findById", true);
  9 + Callback.disableRemoteMethod("findOne", true);
  10 +
  11 + Callback.disableRemoteMethod("deleteById", true);
  12 +
  13 + Callback.disableRemoteMethod("confirm", true);
  14 + Callback.disableRemoteMethod("count", true);
  15 + Callback.disableRemoteMethod("exists", true);
  16 + Callback.disableRemoteMethod("resetPassword", true);
  17 +
  18 + Callback.disableRemoteMethod('__count__accessTokens', false);
  19 + Callback.disableRemoteMethod('__create__accessTokens', false);
  20 + Callback.disableRemoteMethod('__delete__accessTokens', false);
  21 + Callback.disableRemoteMethod('__destroyById__accessTokens', false);
  22 + Callback.disableRemoteMethod('__findById__accessTokens', false);
  23 + Callback.disableRemoteMethod('__get__accessTokens', false);
  24 + Callback.disableRemoteMethod('__updateById__accessTokens', false);
  25 +
  26 + Callback.disableRemoteMethod('create', true); // Removes (POST) /products
  27 + Callback.disableRemoteMethod('upsert', true); // Removes (PUT) /products
  28 + Callback.disableRemoteMethod('deleteById', true); // Removes (DELETE) /products/:id
  29 + Callback.disableRemoteMethod("updateAll", true); // Removes (POST) /products/update
  30 + Callback.disableRemoteMethod("updateAttributes", false); // Removes (PUT) /products/:id
  31 + Callback.disableRemoteMethod('createChangeStream', true); // removes (GET|POST) /products/change-stream
  32 +
  33 + Callback.EmptryParams = function (cb) {
  34 + // cb = callback;
  35 + var success = {
  36 + "resultCode": 20000,
  37 + "resultDescription":"Success"
  38 + };
  39 + cb(null,success);
  40 + };
  41 + Callback.remoteMethod('EmptryParams',{
  42 + http:{path:'/EmptryParams',verb:'get'},
  43 + returns: {arg: 'data', type: 'object', root: true}
  44 + });
  45 + Callback.HttpPost = function (ctx,cb) {
  46 + // cb = callback;
  47 + var success = {
  48 + "resultCode": 20000,
  49 + "resultDescription":"Success",
  50 + "data":ctx
  51 + };
  52 + cb(null,success);
  53 + };
  54 + Callback.remoteMethod('HttpPost',{
  55 + http:{path:'/HttpPost',verb:'post'},
  56 + accepts: { arg: 'ctx', type: 'object', default: {
  57 + "string": "string",
  58 + "number": 12345,
  59 + "array": ['string',1234],
  60 + "object": {
  61 + "string":"string",
  62 + "number":1234
  63 + }
  64 + },http: { source: 'body' }},
  65 + returns: {arg: 'data', type: 'object', root: true}
  66 + });
  67 + Callback.HttpGet = function (ctx,cb) {
  68 + // cb = callback;
  69 +
  70 + var success = {
  71 + "resultCode": 20000,
  72 + "resultDescription":"Success",
  73 + "Try it on":"http://localhost:3232/api/callbacks/models1/5555/models2/6666",
  74 + "data":ctx
  75 +
  76 + };
  77 + cb(null,success);
  78 + };
  79 + Callback.remoteMethod('HttpGet',{
  80 + http:{path:'/models1/:params1/models2/:params2',verb:'get'},
  81 + accepts: { arg: 'ctx', type: 'object', http: function(ctx) {
  82 + // รับข้อมุลมาใส่ไว้ใน ctx
  83 + // 1. รับข้อมูล object ที่ส่งมาโดยใช้ express
  84 + var req = ctx.req;
  85 +
  86 + /* 2. Get ข้อมูลแบบ params
  87 + * params คือค่าที่ส่งมากับ url ex http://localhost/Item/params1/params2
  88 + * รับค่ามาตั้งแต่ http:{path:'/: ตัวแปรที่รับค่าเก็บไว้ /: ตัวแปรที่รับค่าเก็บไว้
  89 +
  90 + */
  91 + var params = {
  92 + "params1":req.params.params1,
  93 + "params2":req.params.params2
  94 + };
  95 + return params;
  96 + } } ,
  97 + returns: {arg: 'data', type: 'object', root: true}
  98 + });
  99 +};
... ...
common/models/callback.json 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +{
  2 + "name": "callback",
  3 + "base": "PersistedModel",
  4 + "idInjection": true,
  5 + "options": {
  6 + "validateUpsert": true
  7 + },
  8 + "properties": {},
  9 + "validations": [],
  10 + "relations": {},
  11 + "acls": [],
  12 + "methods": {}
  13 +}
... ...
common/models/config.js 0 → 100644
... ... @@ -0,0 +1,50 @@
  1 +
  2 +var yaml = require('node-yaml-config');
  3 +var config = yaml.load(__dirname + '/../../config/config.yml');
  4 +module.exports = function(Config) {
  5 +
  6 +
  7 + Config.disableRemoteMethod("create", true);
  8 + Config.disableRemoteMethod("upsert", true);
  9 + Config.disableRemoteMethod("updateAll", true);
  10 + Config.disableRemoteMethod("updateAttributes", false);
  11 +
  12 + Config.disableRemoteMethod("find", true);
  13 + Config.disableRemoteMethod("findById", true);
  14 + Config.disableRemoteMethod("findOne", true);
  15 +
  16 + Config.disableRemoteMethod("deleteById", true);
  17 +
  18 + Config.disableRemoteMethod("confirm", true);
  19 + Config.disableRemoteMethod("count", true);
  20 + Config.disableRemoteMethod("exists", true);
  21 + Config.disableRemoteMethod("resetPassword", true);
  22 +
  23 + Config.disableRemoteMethod('__count__accessTokens', false);
  24 + Config.disableRemoteMethod('__create__accessTokens', false);
  25 + Config.disableRemoteMethod('__delete__accessTokens', false);
  26 + Config.disableRemoteMethod('__destroyById__accessTokens', false);
  27 + Config.disableRemoteMethod('__findById__accessTokens', false);
  28 + Config.disableRemoteMethod('__get__accessTokens', false);
  29 + Config.disableRemoteMethod('__updateById__accessTokens', false);
  30 +
  31 + Config.disableRemoteMethod('create', true); // Removes (POST) /products
  32 + Config.disableRemoteMethod('upsert', true); // Removes (PUT) /products
  33 + Config.disableRemoteMethod('deleteById', true); // Removes (DELETE) /products/:id
  34 + Config.disableRemoteMethod("updateAll", true); // Removes (POST) /products/update
  35 + Config.disableRemoteMethod("updateAttributes", false); // Removes (PUT) /products/:id
  36 + Config.disableRemoteMethod('createChangeStream', true); // removes (GET|POST) /products/change-stream
  37 +
  38 + Config.HttpGet = function (cb) {
  39 + var success = {
  40 + "config":config.server.config,
  41 + "docs":config.server.docs,
  42 + "directory":config.server.directory
  43 + };
  44 + cb(null,success);
  45 + };
  46 + Config.remoteMethod('HttpGet',{
  47 + http:{path:'/config',verb:'get'},
  48 + returns: {arg: 'data', type: 'object', root: true}
  49 + });
  50 +};
... ...
common/models/config.json 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +{
  2 + "name": "config",
  3 + "base": "PersistedModel",
  4 + "idInjection": true,
  5 + "options": {
  6 + "validateUpsert": true
  7 + },
  8 + "properties": {},
  9 + "validations": [],
  10 + "relations": {},
  11 + "acls": [],
  12 + "methods": {}
  13 +}
... ...
common/models/files.js 0 → 100644
... ... @@ -0,0 +1,70 @@
  1 +var fs_ex = require('fs.extra');
  2 +var fs = require('fs');
  3 +var console = process.console;
  4 +module.exports = function(Files) {
  5 +
  6 + Files.disableRemoteMethod("create", true);
  7 + Files.disableRemoteMethod("upsert", true);
  8 + Files.disableRemoteMethod("updateAll", true);
  9 + Files.disableRemoteMethod("updateAttributes", false);
  10 +
  11 + Files.disableRemoteMethod("find", true);
  12 + Files.disableRemoteMethod("findById", true);
  13 + Files.disableRemoteMethod("findOne", true);
  14 +
  15 + Files.disableRemoteMethod("deleteById", true);
  16 +
  17 + Files.disableRemoteMethod("confirm", true);
  18 + Files.disableRemoteMethod("count", true);
  19 + Files.disableRemoteMethod("exists", true);
  20 + Files.disableRemoteMethod("resetPassword", true);
  21 +
  22 + Files.disableRemoteMethod('__count__accessTokens', false);
  23 + Files.disableRemoteMethod('__create__accessTokens', false);
  24 + Files.disableRemoteMethod('__delete__accessTokens', false);
  25 + Files.disableRemoteMethod('__destroyById__accessTokens', false);
  26 + Files.disableRemoteMethod('__findById__accessTokens', false);
  27 + Files.disableRemoteMethod('__get__accessTokens', false);
  28 + Files.disableRemoteMethod('__updateById__accessTokens', false);
  29 +
  30 + Files.disableRemoteMethod('create', true); // Removes (POST) /products
  31 + Files.disableRemoteMethod('upsert', true); // Removes (PUT) /products
  32 + Files.disableRemoteMethod('deleteById', true); // Removes (DELETE) /products/:id
  33 + Files.disableRemoteMethod("updateAll", true); // Removes (POST) /products/update
  34 + Files.disableRemoteMethod("updateAttributes", false); // Removes (PUT) /products/:id
  35 + Files.disableRemoteMethod('createChangeStream', true); // removes (GET|POST) /products/change-stream
  36 +
  37 +
  38 + Files.Files = function(ctx,cb){
  39 + var path = __dirname+'/../uploads/upload';
  40 + console.log(path);
  41 + fs.readFile(path+'.txt', 'utf8', function (err, body) {
  42 + if (err){
  43 + FnwriteFile(body,ctx)
  44 + }else{
  45 + FnwriteFile(body,ctx)
  46 + }
  47 + });
  48 + };
  49 + function FnwriteFile(body,data){
  50 + var path = __dirname+'/../uploads/upload';
  51 +
  52 + //Do your processing, MD5, send a satellite to the moon, etc.
  53 + fs.writeFile(path+'.txt', body+"\n"+data.data, 'utf8', function (err) {
  54 + if (err) {
  55 + console.log(err);
  56 + }else {
  57 + console.tag('docs').log("Write file complete");
  58 + }
  59 + });
  60 +
  61 + }
  62 + Files.remoteMethod('Files',{
  63 + http:{path:'/Files',verb:'post'},
  64 + accepts: { arg: 'ctx', type: 'object', default: {
  65 + "data":"https://www.npmjs.com/package/fs.extra // https://nodejs.org/api/fs.html"
  66 + },http: { source: 'body' }},
  67 + returns: {arg: 'data', type: 'object', root: true}
  68 + })
  69 +
  70 +};
... ...
common/models/files.json 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +{
  2 + "name": "files",
  3 + "base": "PersistedModel",
  4 + "idInjection": true,
  5 + "options": {
  6 + "validateUpsert": true
  7 + },
  8 + "properties": {},
  9 + "validations": [],
  10 + "relations": {},
  11 + "acls": [],
  12 + "methods": {}
  13 +}
... ...
common/models/item.js
... ... @@ -100,8 +100,11 @@ module.exports = function(Item) {
100 100 Item.Moment = function(cb){
101 101 var this_time = {
102 102 "default": moment().format(),
103   - "DD-MM-YYY":moment().format("DD-MM-YYYY"),
104   - "HH:MM:SS":moment().format("HH:mm:ss")
  103 + "DD-MM-YYYY":moment().format("DD-MM-YYYY"),
  104 + "HH:MM:SS":moment().format("HH:mm:ss"),
  105 + "DDMMYYYY":moment().format("DDMMYYYY"),
  106 + "DD-MM-YYYY HH:II::SS":moment().format("DD-MM-YYYY HH:mm:ss"),
  107 + "YYYYMMDD-HHmmssSSS":moment().format("YYYYMMDD-HHmmssSSS")
105 108 };
106 109 cb(null,this_time);
107 110 };
... ...
common/models/logs.js 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +var console = process.console;
  2 +module.exports = function(Logs) {
  3 + Logs.Logs = function(cb){
  4 + console.tag('TestLog','Logs').file().time().log('http://localhost:3232/logs/');
  5 + console.tag('TestLog','Logs').file().time().warning('http://localhost:3232/logs/');
  6 + console.tag('TestLog','Logs').file().time().error('http://localhost:3232/logs/');
  7 + console.tag('TestLog','Logs').file().time().info('http://localhost:3232/logs/');
  8 + cb(null);
  9 + };
  10 + Logs.remoteMethod('Logs',{
  11 + http:{path:'/Logs',verb:'get'},
  12 + returns: {arg: 'data', type: 'object', root: true}
  13 + });
  14 +
  15 +};
... ...
common/models/logs.json 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +{
  2 + "name": "logs",
  3 + "base": "PersistedModel",
  4 + "idInjection": true,
  5 + "options": {
  6 + "validateUpsert": true
  7 + },
  8 + "properties": {},
  9 + "validations": [],
  10 + "relations": {},
  11 + "acls": [],
  12 + "methods": {}
  13 +}
... ...
common/models/moment.js 0 → 100644
... ... @@ -0,0 +1,55 @@
  1 +
  2 +var moment = require('moment');
  3 +module.exports = function(Moment) {
  4 +
  5 + Moment.disableRemoteMethod("create", true);
  6 + Moment.disableRemoteMethod("upsert", true);
  7 + Moment.disableRemoteMethod("updateAll", true);
  8 + Moment.disableRemoteMethod("updateAttributes", false);
  9 +
  10 + Moment.disableRemoteMethod("find", true);
  11 + Moment.disableRemoteMethod("findById", true);
  12 + Moment.disableRemoteMethod("findOne", true);
  13 +
  14 + Moment.disableRemoteMethod("deleteById", true);
  15 +
  16 + Moment.disableRemoteMethod("confirm", true);
  17 + Moment.disableRemoteMethod("count", true);
  18 + Moment.disableRemoteMethod("exists", true);
  19 + Moment.disableRemoteMethod("resetPassword", true);
  20 +
  21 + Moment.disableRemoteMethod('__count__accessTokens', false);
  22 + Moment.disableRemoteMethod('__create__accessTokens', false);
  23 + Moment.disableRemoteMethod('__delete__accessTokens', false);
  24 + Moment.disableRemoteMethod('__destroyById__accessTokens', false);
  25 + Moment.disableRemoteMethod('__findById__accessTokens', false);
  26 + Moment.disableRemoteMethod('__get__accessTokens', false);
  27 + Moment.disableRemoteMethod('__updateById__accessTokens', false);
  28 +
  29 + Moment.disableRemoteMethod('create', true); // Removes (POST) /products
  30 + Moment.disableRemoteMethod('upsert', true); // Removes (PUT) /products
  31 + Moment.disableRemoteMethod('deleteById', true); // Removes (DELETE) /products/:id
  32 + Moment.disableRemoteMethod("updateAll", true); // Removes (POST) /products/update
  33 + Moment.disableRemoteMethod("updateAttributes", false); // Removes (PUT) /products/:id
  34 + Moment.disableRemoteMethod('createChangeStream', true); // removes (GET|POST) /products/change-stream
  35 +
  36 +
  37 + Moment.Moment = function(cb){
  38 + var this_time = {
  39 + "docs":"http://momentjs.com/docs/",
  40 + "default": moment().format(),
  41 + "DD-MM-YYYY":moment().format("DD-MM-YYYY"),
  42 + "HH:MM:SS":moment().format("HH:mm:ss"),
  43 + "DDMMYYYY":moment().format("DDMMYYYY"),
  44 + "DD-MM-YYYY HH:II::SS":moment().format("DD-MM-YYYY HH:mm:ss"),
  45 + "YYYYMMDD-HHmmssSSS":moment().format("YYYYMMDD-HHmmssSSS")
  46 + };
  47 + cb(null,this_time);
  48 +
  49 + };
  50 + Moment.remoteMethod('Moment',{
  51 + http:{path:'/Moment',verb:'get'},
  52 + returns: {arg: 'data', type: 'object', root: true}
  53 + })
  54 +
  55 +};
... ...
common/models/moment.json 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +{
  2 + "name": "moment",
  3 + "base": "PersistedModel",
  4 + "idInjection": true,
  5 + "options": {
  6 + "validateUpsert": true
  7 + },
  8 + "properties": {},
  9 + "validations": [],
  10 + "relations": {},
  11 + "acls": [],
  12 + "methods": {}
  13 +}
... ...
common/models/promises.js 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +var bluebird = require('bluebird');
  2 +var promise = new Promise(function (resolve,reject) {
  3 + resolve('success')
  4 +})
  5 +module.exports = function(Promises) {
  6 + Promises.Ex = function (cb) {
  7 + promise
  8 + .then(MyFunc1())
  9 + .then(MyFunc2());
  10 +
  11 + };
  12 + function MyFunc1(){
  13 + setTimeout(function(){
  14 + console.log('first');
  15 + return true;
  16 + },1000);
  17 + }
  18 + function MyFunc2(){
  19 + console.log('second');
  20 + }
  21 + Promises.remoteMethod('Ex',{
  22 + http:{path:'/Ex',verb:'get'},
  23 + accepts: { arg: 'ctx', type: 'object' } ,
  24 + returns: {arg: 'data', type: 'object', root: true}
  25 + })
  26 +};
... ...
common/models/promises.json 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +{
  2 + "name": "promises",
  3 + "base": "PersistedModel",
  4 + "idInjection": true,
  5 + "options": {
  6 + "validateUpsert": true
  7 + },
  8 + "properties": {},
  9 + "validations": [],
  10 + "relations": {},
  11 + "acls": [],
  12 + "methods": {}
  13 +}
... ...
common/models/unirest.js 0 → 100644
... ... @@ -0,0 +1,82 @@
  1 +var console = process.console;
  2 +var unirest = require('unirest');
  3 +
  4 +module.exports = function(Unirest) {
  5 +
  6 + Unirest.disableRemoteMethod("create", true);
  7 + Unirest.disableRemoteMethod("upsert", true);
  8 + Unirest.disableRemoteMethod("updateAll", true);
  9 + Unirest.disableRemoteMethod("updateAttributes", false);
  10 +
  11 + Unirest.disableRemoteMethod("find", true);
  12 + Unirest.disableRemoteMethod("findById", true);
  13 + Unirest.disableRemoteMethod("findOne", true);
  14 +
  15 + Unirest.disableRemoteMethod("deleteById", true);
  16 +
  17 + Unirest.disableRemoteMethod("confirm", true);
  18 + Unirest.disableRemoteMethod("count", true);
  19 + Unirest.disableRemoteMethod("exists", true);
  20 + Unirest.disableRemoteMethod("resetPassword", true);
  21 +
  22 + Unirest.disableRemoteMethod('__count__accessTokens', false);
  23 + Unirest.disableRemoteMethod('__create__accessTokens', false);
  24 + Unirest.disableRemoteMethod('__delete__accessTokens', false);
  25 + Unirest.disableRemoteMethod('__destroyById__accessTokens', false);
  26 + Unirest.disableRemoteMethod('__findById__accessTokens', false);
  27 + Unirest.disableRemoteMethod('__get__accessTokens', false);
  28 + Unirest.disableRemoteMethod('__updateById__accessTokens', false);
  29 +
  30 + Unirest.disableRemoteMethod('create', true); // Removes (POST) /products
  31 + Unirest.disableRemoteMethod('upsert', true); // Removes (PUT) /products
  32 + Unirest.disableRemoteMethod('deleteById', true); // Removes (DELETE) /products/:id
  33 + Unirest.disableRemoteMethod("updateAll", true); // Removes (POST) /products/update
  34 + Unirest.disableRemoteMethod("updateAttributes", false); // Removes (PUT) /products/:id
  35 + Unirest.disableRemoteMethod('createChangeStream', true); // removes (GET|POST) /products/change-stream
  36 +
  37 +
  38 + Unirest.HttpPost = function (ctx,cb) {
  39 + console.log(ctx);
  40 + var success = {
  41 + "resultCode": 20000,
  42 + "resultDescription":"Success",
  43 + "data":ctx
  44 + };
  45 + console.log(success);
  46 + cb(null,success);
  47 + };
  48 + Unirest.remoteMethod('HttpPost',{
  49 + http:{path:'/HttpPost',verb:'post'},
  50 + accepts: { arg: 'ctx', type: 'object',http: { source: 'body' }},
  51 + returns: {arg: 'data', type: 'object', root: true}
  52 + });
  53 + Unirest.HttpGet = function (ctx,cb) {
  54 + // cb = callback;
  55 + var data = {
  56 + "data":ctx
  57 + };
  58 + unirest.post('http://localhost:3232/api/unirests/HttpPost')
  59 + .send(data)
  60 + .end(function (response) {
  61 + response.body.data.docs = "http://unirest.io/nodejs.html";
  62 + console.log(response.body);
  63 + cb(null,response.body)
  64 + });
  65 + };
  66 + Unirest.remoteMethod('HttpGet',{
  67 + http:{path:'/unirest/:data',verb:'get'},
  68 + accepts: { arg: 'ctx', type: 'string', http: function(ctx) {
  69 + // รับข้อมุลมาใส่ไว้ใน ctx
  70 + // 1. รับข้อมูล object ที่ส่งมาโดยใช้ express
  71 + var req = ctx.req;
  72 +
  73 + /* 2. Get ข้อมูลแบบ params
  74 + * params คือค่าที่ส่งมากับ url ex http://localhost/Item/params1/params2
  75 + * รับค่ามาตั้งแต่ http:{path:'/: ตัวแปรที่รับค่าเก็บไว้ /: ตัวแปรที่รับค่าเก็บไว้
  76 +
  77 + */
  78 + return req.params.data;
  79 + } } ,
  80 + returns: {arg: 'data', type: 'object', root: true}
  81 + });
  82 +};
... ...
common/models/unirest.json 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +{
  2 + "name": "unirest",
  3 + "base": "PersistedModel",
  4 + "idInjection": true,
  5 + "options": {
  6 + "validateUpsert": true
  7 + },
  8 + "properties": {},
  9 + "validations": [],
  10 + "relations": {},
  11 + "acls": [],
  12 + "methods": {}
  13 +}
... ...
common/models/uploads.txt 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +undefined
  2 +string
  3 +string
0 4 \ No newline at end of file
... ...
common/uploads/upload.txt 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +undefined
  2 +string
  3 +string
  4 +string
  5 +https://www.npmjs.com/package/fs.extra // https://nodejs.org/api/fs.html
  6 +https://www.npmjs.com/package/fs.extra // https://nodejs.org/api/fs.html
0 7 \ No newline at end of file
... ...
config/config.yml 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +developer:
  2 + server:
  3 + config: 'Edit here'
  4 + docs: 'https://cloud.google.com/appengine/docs/flexible/nodejs/configuring-your-app-with-app-yaml'
  5 + directory : 'config/config.yml'
0 6 \ No newline at end of file
... ...
package.json
... ... @@ -8,10 +8,12 @@
8 8 "posttest": "nsp check"
9 9 },
10 10 "dependencies": {
  11 + "bluebird": "^3.4.1",
11 12 "body-parser": "^1.15.2",
12 13 "compression": "^1.0.3",
13 14 "cors": "^2.5.2",
14 15 "ejs": "^2.4.2",
  16 + "fs.extra": "^1.3.2",
15 17 "helmet": "^1.3.0",
16 18 "loopback": "^2.22.0",
17 19 "loopback-boot": "^2.6.5",
... ... @@ -20,6 +22,7 @@
20 22 "loopback-connector-mysql": "^2.3.0",
21 23 "loopback-datasource-juggler": "^2.39.0",
22 24 "moment": "^2.13.0",
  25 + "node-yaml-config": "0.0.4",
23 26 "path": "^0.12.7",
24 27 "scribe-js": "^2.0.4",
25 28 "serve-favicon": "^2.0.1",
... ...
server/boot/myapp.js 0 → 100644
... ... @@ -0,0 +1,45 @@
  1 +/**
  2 + * Created by Develop-SC on 11/7/2559.
  3 + */
  4 +module.exports = function(app) {
  5 +
  6 + function modifyResponse(ctx, model, next) {
  7 + var response;
  8 + var status = ctx.res.statusCode;
  9 + console.log(status);
  10 + console.log(model);
  11 + if(status === 200){
  12 + response = {
  13 + "resultCode":model.resultCode ? model.resultCode : "20000",
  14 + "resultDescript": model.resultDescript ? model.resultDescript : "Success",
  15 + "data": model.data ? model.data : model
  16 + };
  17 + }else{
  18 + response = {
  19 + "resultCode":model.resultCode ? model.resultCode : "20000",
  20 + "resultDescript": model.resultDescript ? model.resultDescript : "Success",
  21 + "data": model.data ? model.data : model
  22 + };
  23 +
  24 + }
  25 + ctx.res.send(response)
  26 + .end();
  27 + }
  28 + function modifyError(ctx,model,next){
  29 + var fail = {
  30 + "resultCode": 50000,
  31 + "resultDescription":"fail"
  32 + };
  33 + ctx.res.send(fail).end();
  34 + }
  35 + /*function validate(ctx,model,next){
  36 + var fail = {
  37 + "resultCode": 50000,
  38 + "resultDescription":"fail"
  39 + };
  40 + ctx.res.send(fail).end();
  41 + }
  42 + app.models.beforeRemote('**', validate);*/
  43 + app.models.Logs.afterRemote('**', modifyResponse);
  44 + app.models.Logs.afterRemoteError('**', modifyError);
  45 +};
0 46 \ No newline at end of file
... ...
server/config.json
1 1 {
2 2 "restApiRoot": "/api",
3 3 "host": "0.0.0.0",
4   - "port": 3000,
  4 + "port": 3232,
5 5 "remoting": {
6 6 "context": {
7 7 "enableHttpContext": false
... ...
server/datasources.json
... ... @@ -22,86 +22,5 @@
22 22 "name": "radius",
23 23 "user": "radius",
24 24 "connector": "mysql"
25   - },
26   - "account": {
27   - "host": "server8.sourcecode.co.th",
28   - "port": 3306,
29   - "url": "",
30   - "database": "account",
31   - "password": "A83kKhoAH4jcEHMY",
32   - "name": "account",
33   - "user": "npm_account",
34   - "connector": "mysql"
35   - },
36   - "refill": {
37   - "host": "server8.sourcecode.co.th",
38   - "port": 3306,
39   - "url": "",
40   - "database": "refill",
41   - "password": "Fe8Vf63LtdGQaFtd",
42   - "name": "refill",
43   - "user": "npm_refill",
44   - "connector": "mysql"
45   - },
46   - "smartquotation": {
47   - "host": "server8.sourcecode.co.th",
48   - "port": 3306,
49   - "url": "",
50   - "database": "smartquotation",
51   - "password": "Bwa7Z6ZRosU4RuAH",
52   - "name": "smartquotation",
53   - "user": "npm_smtquot",
54   - "connector": "mysql"
55   - },
56   - "smartzone": {
57   - "host": "server8.sourcecode.co.th",
58   - "port": 3306,
59   - "url": "",
60   - "database": "smartzone",
61   - "password": "pADobokFAoPC384B",
62   - "name": "account",
63   - "user": "npm_szv3",
64   - "connector": "mysql"
65   - },
66   - "smartzonev4": {
67   - "host": "server8.sourcecode.co.th",
68   - "port": 3306,
69   - "url": "",
70   - "database": "smartzonev4",
71   - "password": "Q7TsWo7UNbCsi3sb",
72   - "name": "smartzonev4",
73   - "user": "npm_szv4",
74   - "connector": "mysql"
75   - },
76   - "thespecialdress": {
77   - "host": "server8.sourcecode.co.th",
78   - "port": 3306,
79   - "url": "",
80   - "database": "thespecialdress",
81   - "password": "bXGhkLoTJ9atAx72",
82   - "name": "thespecialdress",
83   - "user": "npm_tsd",
84   - "connector": "mysql"
85   - },
86   - "thespecialdress_wp": {
87   - "host": "server8.sourcecode.co.th",
88   - "port": 3306,
89   - "url": "",
90   - "database": "thespecialdress_wp",
91   - "password": "gAUmK7Jcvq4F7CUs",
92   - "name": "thespecialdress_wp",
93   - "user": "npm_tsdwp",
94   - "connector": "mysql"
95   - },
96   - "vtigercrm510": {
97   - "host": "server8.sourcecode.co.th",
98   - "port": 3306,
99   - "url": "",
100   - "database": "vtigercrm510",
101   - "password": "X6UUfWM8GJEPBzv3",
102   - "name": "vtigercrm510",
103   - "user": "npm_vtiger",
104   - "connector": "mysql"
105 25 }
106 26 }
107   -
... ...
server/model-config.json
... ... @@ -43,5 +43,33 @@
43 43 "order": {
44 44 "dataSource": "mongodb",
45 45 "public": true
  46 + },
  47 + "promises": {
  48 + "dataSource": "db",
  49 + "public": true
  50 + },
  51 + "logs": {
  52 + "dataSource": "db",
  53 + "public": true
  54 + },
  55 + "callback": {
  56 + "dataSource": "db",
  57 + "public": true
  58 + },
  59 + "moment": {
  60 + "dataSource": "db",
  61 + "public": true
  62 + },
  63 + "files": {
  64 + "dataSource": "db",
  65 + "public": true
  66 + },
  67 + "unirest": {
  68 + "dataSource": "db",
  69 + "public": true
  70 + },
  71 + "config": {
  72 + "dataSource": "db",
  73 + "public": true
46 74 }
47 75 }
... ...