Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
console
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
console
Commits
f2d44586
Commit
f2d44586
authored
Jan 05, 2017
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:mycard/mycard-console
parents
ed50f74d
3188a486
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
106 additions
and
34 deletions
+106
-34
app/app-detail.component.ts
app/app-detail.component.ts
+1
-1
app/app-locales.component.ts
app/app-locales.component.ts
+1
-1
app/app-packages.component.ts
app/app-packages.component.ts
+1
-1
app/app.component.ts
app/app.component.ts
+1
-1
app/app.service.ts
app/app.service.ts
+52
-8
app/apps.component.ts
app/apps.component.ts
+1
-1
db/mongo.ts
db/mongo.ts
+1
-0
koa/errors.ts
koa/errors.ts
+5
-1
models/app.ts
models/app.ts
+1
-1
models/errors.ts
models/errors.ts
+19
-5
routes/apps.ts
routes/apps.ts
+15
-10
server.ts
server.ts
+8
-4
No files found.
app/app-detail.component.ts
View file @
f2d44586
...
...
@@ -19,7 +19,7 @@ export class AppDetailComponent implements OnInit {
async
ngOnInit
()
{
this
.
route
.
parent
.
params
.
switchMap
((
params
:
Params
)
=>
this
.
appService
.
getApp
(
params
[
'
id
'
]))
.
switchMap
((
params
:
Params
)
=>
this
.
appService
.
find
(
params
[
'
id
'
]))
.
subscribe
(
app
=>
{
this
.
app
=
app
;
});
...
...
app/app-locales.component.ts
View file @
f2d44586
...
...
@@ -23,7 +23,7 @@ export class AppLocalesComponent implements OnInit {
async
ngOnInit
()
{
this
.
route
.
parent
.
params
.
switchMap
((
params
:
Params
)
=>
this
.
appService
.
getApp
(
params
[
'
id
'
]))
.
switchMap
((
params
:
Params
)
=>
this
.
appService
.
find
(
params
[
'
id
'
]))
.
subscribe
(
app
=>
{
this
.
app
=
app
;
this
.
locales
=
Object
.
keys
(
app
.
name
);
...
...
app/app-packages.component.ts
View file @
f2d44586
...
...
@@ -19,7 +19,7 @@ export class AppPackagesComponent implements OnInit {
async
ngOnInit
()
{
this
.
route
.
parent
.
params
.
switchMap
((
params
:
Params
)
=>
this
.
appService
.
getApp
(
params
[
'
id
'
]))
.
switchMap
((
params
:
Params
)
=>
this
.
appService
.
find
(
params
[
'
id
'
]))
.
subscribe
(
app
=>
{
this
.
app
=
app
;
});
...
...
app/app.component.ts
View file @
f2d44586
...
...
@@ -15,7 +15,7 @@ export class AppComponent implements OnInit {
ngOnInit
()
{
this
.
route
.
params
.
switchMap
((
params
:
Params
)
=>
this
.
appService
.
getApp
(
params
[
'
id
'
]))
.
switchMap
((
params
:
Params
)
=>
this
.
appService
.
find
(
params
[
'
id
'
]))
.
subscribe
(
app
=>
{
this
.
app
=
app
;
});
...
...
app/app.service.ts
View file @
f2d44586
import
{
Injectable
}
from
'
@angular/core
'
;
import
App
from
'
../models/browserapp
'
;
import
{
Http
,
RequestOptions
,
Headers
}
from
'
@angular/http
'
;
import
{
Http
,
RequestOptions
,
Headers
,
Response
}
from
'
@angular/http
'
;
import
'
rxjs/add/operator/toPromise
'
;
import
{
Observable
}
from
'
rxjs/Rx
'
;
/**
* Created by weijian on 2016/12/30.
*/
function
addJsonOptions
(
options
?:
RequestOptions
):
RequestOptions
{
if
(
options
)
{
options
.
headers
.
append
(
'
Content-Type
'
,
'
application/json
'
);
}
else
{
let
headers
=
new
Headers
({
'
Content-Type
'
:
'
application/json
'
})
options
=
new
RequestOptions
({
headers
:
headers
});
}
return
options
;
}
@
Injectable
()
export
class
AppService
{
constructor
(
private
http
:
Http
)
{
}
getApps
():
Promise
<
App
[]
>
{
return
this
.
http
.
get
(
'
http://localhost:8000/apps
'
).
map
((
response
)
=>
response
.
json
().
map
((
app
:
any
)
=>
new
App
(
app
))).
toPromise
();
all
():
Promise
<
App
[]
>
{
return
this
.
http
.
get
(
'
http://localhost:8000/apps
'
)
.
map
((
response
)
=>
{
return
response
.
json
().
map
((
app
:
any
)
=>
new
App
(
app
));
}).
catch
(
this
.
handleError
)
.
toPromise
();
}
getApp
(
id
:
string
):
Promise
<
App
>
{
return
this
.
http
.
get
(
`http://localhost:8000/apps/
${
id
}
`
).
map
((
response
)
=>
new
App
(
response
.
json
())).
toPromise
();
handleError
(
error
:
Response
|
any
)
{
// In a real world app, we might use a remote logging infrastructure
let
err
:
Error
;
if
(
error
instanceof
Response
)
{
err
=
error
.
json
()
||
{};
}
else
{
err
=
new
Error
(
'
Unknown Error
'
);
}
return
Observable
.
throw
(
err
);
}
save
(
app
:
App
):
Promise
<
any
>
{
let
headers
=
new
Headers
({
'
Content-Type
'
:
'
application/json
'
});
let
options
=
new
RequestOptions
({
headers
:
headers
});
return
this
.
http
.
post
(
`http://localhost:8000/apps/
${
app
.
id
}
`
,
app
,
options
).
map
((
response
)
=>
response
.
json
()).
toPromise
();
let
options
=
addJsonOptions
();
return
this
.
http
.
post
(
`http://localhost:8000/apps/
${
app
.
id
}
`
,
app
,
options
)
.
map
((
response
)
=>
response
.
json
())
.
catch
(
this
.
handleError
)
.
toPromise
();
}
update
(
app
:
App
)
{
let
options
=
addJsonOptions
();
return
this
.
http
.
patch
(
`http://localhost:8000/apps/
${
app
.
id
}
`
,
app
,
options
)
.
map
((
response
)
=>
response
.
json
())
.
catch
(
this
.
handleError
)
.
toPromise
();
}
remove
(
app
:
App
)
{
return
this
.
http
.
delete
(
`http://localhost:8000/apps/
${
app
.
id
}
`
)
.
map
((
response
)
=>
response
.
json
())
.
catch
(
this
.
handleError
)
.
toPromise
();
}
find
(
id
:
string
):
Promise
<
App
>
{
return
this
.
http
.
get
(
`http://localhost:8000/apps/
${
id
}
`
)
.
map
((
response
)
=>
response
.
json
)
.
catch
(
this
.
handleError
)
.
toPromise
();
}
}
app/apps.component.ts
View file @
f2d44586
...
...
@@ -22,7 +22,7 @@ export class AppsComponent implements OnInit {
}
async
getApps
()
{
this
.
apps
=
await
this
.
appService
.
getApps
();
this
.
apps
=
await
this
.
appService
.
all
();
}
async
create_app
()
{
...
...
db/mongo.ts
View file @
f2d44586
...
...
@@ -32,6 +32,7 @@ export class Model {
static
async
findOne
(
query
:
Object
):
Promise
<
any
|
null
>
{
let
collection
=
await
this
.
getCollection
();
let
result
=
await
collection
.
find
(
query
).
limit
(
1
).
next
();
console
.
log
(
result
,
query
,
this
.
dbName
);
if
(
result
)
{
return
new
this
(
result
);
}
else
{
...
...
koa/errors.ts
View file @
f2d44586
...
...
@@ -19,5 +19,9 @@ export class BadRequest extends KoaError {
super
(
msg
,
400
);
}
}
export
const
InternalError
=
new
KoaError
(
STATUS_CODES
[
500
],
500
);
export
class
InternalError
extends
KoaError
{
constructor
(
public
error
:
Error
)
{
super
(
STATUS_CODES
[
500
],
500
);
}
}
models/app.ts
View file @
f2d44586
...
...
@@ -28,7 +28,7 @@ export class App extends Model {
async
checkExists
()
{
let
app
=
await
App
.
findOne
({
id
:
this
.
id
});
if
(
app
)
{
throw
new
ModelExistsError
(
this
.
id
);
throw
new
ModelExistsError
(
`App
${
this
.
id
}
exists`
);
}
}
...
...
models/errors.ts
View file @
f2d44586
import
{
KoaError
}
from
'
../koa/errors
'
;
/**
* Created by weijian on 2017/1/4.
*/
class
ModelError
extends
Error
{
export
abstract
class
ModelError
extends
KoaError
{
abstract
errCode
:
string
;
constructor
(
msg
:
string
,
status
:
number
)
{
super
(
msg
,
status
);
}
}
export
class
ModelExistsError
extends
ModelError
{
errCode
:
string
=
'
ERROR_MODULE_EXISTS
'
;
constructor
(
msg
:
string
)
{
super
(
msg
);
super
(
msg
,
400
);
}
}
export
class
ModelExistsError
extends
Error
{
constructor
(
id
:
string
)
{
super
(
`App
${
id
}
already exists`
);
export
class
ModelInvalidError
extends
ModelError
{
errCode
:
string
=
'
ERROR_MODEL_INVALID
'
;
constructor
(
msg
:
string
)
{
super
(
msg
,
400
);
}
}
routes/apps.ts
View file @
f2d44586
...
...
@@ -2,10 +2,9 @@
* Created by weijian on 2016/12/28.
*/
import
Router
=
require
(
'
koa-router
'
);
import
{
NotFound
,
BadRequest
,
InternalError
}
from
'
../koa/errors
'
;
import
{
Model
}
from
'
../db/mongo
'
;
import
{
NotFound
,
InternalError
}
from
'
../koa/errors
'
;
import
{
App
}
from
'
../models/app
'
;
import
{
ModelE
xists
Error
}
from
'
../models/errors
'
;
import
{
ModelE
rror
,
ModelInvalid
Error
}
from
'
../models/errors
'
;
const
router
=
new
Router
();
router
.
get
(
'
/apps
'
,
async
(
ctx
,
next
)
=>
{
...
...
@@ -22,33 +21,39 @@ router.get('/apps/:id', async(ctx, next) => {
});
router
.
post
(
'
/apps/:id
'
,
async
(
ctx
,
next
)
=>
{
if
(
!
ctx
.
request
.
body
.
id
||
ctx
.
params
.
id
!==
ctx
.
request
.
body
.
id
)
{
throw
new
ModelInvalidError
(
'
App id not same
'
);
}
let
app
=
new
App
(
ctx
.
request
.
body
);
try
{
ctx
.
body
=
await
app
.
save
();
}
catch
(
e
)
{
if
(
e
instanceof
ModelE
xistsE
rror
)
{
throw
new
BadRequest
(
`App
${
ctx
.
params
.
id
}
already exists`
)
;
if
(
e
instanceof
ModelError
)
{
throw
e
;
}
else
{
throw
InternalError
;
throw
new
InternalError
(
e
)
;
}
}
});
router
.
patch
(
'
/apps/:id
'
,
async
(
ctx
,
next
)
=>
{
let
app
:
App
|
null
=
await
Model
.
findOne
({
id
:
ctx
.
params
.
id
});
let
app
:
App
|
null
=
await
App
.
findOne
({
id
:
ctx
.
params
.
id
});
if
(
!
app
)
{
throw
new
NotFound
(
`App
${
ctx
.
params
.
id
}
Not Found`
);
}
if
(
!
ctx
.
request
.
body
.
id
||
ctx
.
request
.
body
.
id
!==
app
.
id
)
{
throw
new
ModelInvalidError
(
'
Can not change AppID
'
);
}
Object
.
assign
(
app
,
ctx
.
request
.
body
);
await
app
.
save
();
ctx
.
body
=
await
app
.
save
();
});
router
.
delete
(
'
/apps/:id
'
,
async
(
ctx
,
next
)
=>
{
let
result
=
await
App
.
remove
({
id
:
ctx
.
params
.
id
});
if
(
!
result
.
deletedCount
)
{
if
(
!
result
.
result
.
n
)
{
throw
new
NotFound
(
`App
${
ctx
.
params
.
id
}
Not Found`
);
}
ctx
.
body
=
result
;
ctx
.
body
=
result
.
result
;
});
export
default
router
;
server.ts
View file @
f2d44586
...
...
@@ -26,14 +26,18 @@ app.use(async(ctx, next) => {
await
next
();
}
catch
(
err
)
{
// will only respond with JSON
console
.
log
(
err
.
status
);
ctx
.
status
=
err
.
status
||
500
;
ctx
.
body
=
{
message
:
err
.
message
message
:
err
.
message
,
};
if
(
ctx
.
response
.
status
>=
400
)
{
logger
.
warn
(
err
);
}
else
if
(
ctx
.
response
.
status
>=
500
)
{
if
(
err
.
errCode
)
{
ctx
.
body
[
'
errCode
'
]
=
err
.
errCode
;
}
if
(
ctx
.
response
.
status
>=
500
)
{
logger
.
error
(
err
);
}
else
if
(
ctx
.
response
.
status
>=
400
)
{
logger
.
warn
(
err
);
}
}
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment