Skip to content

Commit 3bca547

Browse files
authored
Merge pull request #65 from TaloDev/develop
Clay and MikroORM upgrades
2 parents 65b5780 + 0d7bd14 commit 3bca547

File tree

109 files changed

+1044
-1797
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+1044
-1797
lines changed

.github/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
hangelog:
1+
changelog:
22
exclude:
33
labels:
44
- release
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
to: "<%= (typeof api !== 'undefined') ? `src/policies/api/${name}s-api.policy.ts` : null %>"
2+
to: "<%= (typeof api !== 'undefined') ? `src/policies/api/${name}-api.policy.ts` : null %>"
33
---
44
import Policy from '../policy'
5-
import { ServicePolicyResponse } from 'koa-rest-services'
5+
import { PolicyResponse } from 'koa-clay'
66

7-
export default class <%= h.changeCase.pascal(name) %>sAPIPolicy extends Policy {
8-
async post(): Promise<ServicePolicyResponse> {
7+
export default class <%= h.changeCase.pascal(name) %>APIPolicy extends Policy {
8+
async post(): Promise<PolicyResponse> {
99
return await this.hasScope('write:<%= h.changeCase.camel(name) %>s')
1010
}
1111
}

_templates/service/new/api-route-import.ejs.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ inject: true
33
to: "<%= (typeof api !== 'undefined') ? 'src/config/api-routes.ts' : null %>"
44
after: import \{ service \}
55
---
6-
import <%= h.changeCase.pascal(name) %>sAPIService from '../services/api/<%= name %>s-api.service'
6+
import <%= h.changeCase.pascal(name) %>APIService from '../services/api/<%= name %>-api.service'

_templates/service/new/api-route.ejs.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ inject: true
33
to: "<%= (typeof api !== 'undefined') ? 'src/config/api-routes.ts' : null %>"
44
before: app\.use\(service
55
---
6-
app.use(service('/v1/<%= name %>s', new <%= h.changeCase.pascal(name) %>sAPIService()))
6+
app.use(service('/v1/<%= name %>s', new <%= h.changeCase.pascal(name) %>APIService()))

_templates/service/new/api-service-test.ejs.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
2-
to: "<%= (typeof api !== 'undefined') ? `tests/services/_api/${name}s-api/post.test.ts` : null %>"
2+
to: "<%= (typeof api !== 'undefined') ? `tests/services/_api/${name}-api/post.test.ts` : null %>"
33
---
44
import { EntityManager } from '@mikro-orm/core'
55
import Koa from 'koa'
66
import init from '../../../../src/index'
77
import request from 'supertest'
88
import APIKey, { APIKeyScope } from '../../../../src/entities/api-key'
9-
import { createToken } from '../../../../src/services/api-keys.service'
9+
import { createToken } from '../../../../src/services/api-key.service'
1010
import UserFactory from '../../../fixtures/UserFactory'
1111
import GameFactory from '../../../fixtures/GameFactory'
1212

1313
const baseUrl = '/v1/<%= name %>s'
1414

15-
describe('<%= h.changeCase.sentenceCase(name) %>s API service - post', () => {
15+
describe('<%= h.changeCase.sentenceCase(name) %> API service - post', () => {
1616
let app: Koa
1717
let apiKey: APIKey
1818
let token: string
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
---
2-
to: "<%= (typeof api !== 'undefined') ? `src/services/api/${name}s-api.service.ts` : null %>"
2+
to: "<%= (typeof api !== 'undefined') ? `src/services/api/${name}-api.service.ts` : null %>"
33
---
4-
import { HasPermission, ServiceRequest, ServiceResponse } from 'koa-rest-services'
5-
import <%= h.changeCase.pascal(name) %>sAPIPolicy from '../../policies/api/<%= name %>s-api.policy'
6-
import <%= h.changeCase.pascal(name) %>sService from '../<%= name %>s.service'
4+
import { HasPermission, Request, Response } from 'koa-clay'
5+
import <%= h.changeCase.pascal(name) %>APIPolicy from '../../policies/api/<%= name %>-api.policy'
6+
import <%= h.changeCase.pascal(name) %>Service from '../<%= name %>.service'
77
import APIService from './api-service'
88
import APIKey from '../../entities/api-key'
99

10-
export default class <%= h.changeCase.pascal(name) %>APIService extends APIService<<%= h.changeCase.pascal(name) %>sService> {
10+
export default class <%= h.changeCase.pascal(name) %>APIService extends APIService<<%= h.changeCase.pascal(name) %>Service> {
1111
constructor() {
1212
super('<%= name %>s')
1313
}
1414

15-
@HasPermission(<%= h.changeCase.pascal(name) %>sAPIPolicy, 'post')
16-
async post(req: ServiceRequest): Promise<ServiceResponse> {
15+
@HasPermission(<%= h.changeCase.pascal(name) %>APIPolicy, 'post')
16+
async post(req: Request): Promise<Response> {
1717
const key: APIKey = await this.getAPIKey(req.ctx)
18-
req.body = {
19-
...req.body,
20-
gameId: key.game.id
21-
}
22-
23-
return await this.forwardRequest('post', req)
18+
return await this.forwardRequest('post', req, {
19+
body: {
20+
gameId: key.game.id
21+
}
22+
})
2423
}
2524
}

_templates/service/new/policy.ejs.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
2-
to: src/policies/<%= name %>s.policy.ts
2+
to: src/policies/<%= name %>.policy.ts
33
---
44
import Policy from './policy'
5-
import { ServicePolicyResponse, ServicePolicyDenial } from 'koa-rest-services'
5+
import { PolicyResponse, PolicyDenial } from 'koa-clay'
66
import { UserType } from '../entities/user'
77

8-
export default class <%= h.changeCase.pascal(name) %>sPolicy extends Policy {
9-
async get(): Promise<ServicePolicyResponse> {
8+
export default class <%= h.changeCase.pascal(name) %>Policy extends Policy {
9+
async get(): Promise<PolicyResponse> {
1010
return true
1111
}
1212

13-
async post(): Promise<ServicePolicyResponse> {
13+
async post(): Promise<PolicyResponse> {
1414
const user = await this.getUser()
15-
if (user.type === UserType.DEMO) return new ServicePolicyDenial({ message: 'Demo accounts cannot create <%= h.changeCase.noCase(name) %>s' })
15+
if (user.type === UserType.DEMO) return new PolicyDenial({ message: 'Demo accounts cannot create <%= h.changeCase.noCase(name) %>s' })
1616

1717
return true
1818
}

_templates/service/new/protected-route-import.ejs.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ inject: true
33
to: src/config/protected-routes.ts
44
after: import \{ service \}
55
---
6-
import <%= h.changeCase.pascal(name) %>sService from '../services/<%= name %>s.service'
6+
import <%= h.changeCase.pascal(name) %>Service from '../services/<%= name %>.service'

_templates/service/new/protected-route.ejs.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ inject: true
33
to: src/config/protected-routes.ts
44
before: app\.use\(service
55
---
6-
app.use(service('/<%= name %>s', new <%= h.changeCase.pascal(name) %>sService()))
6+
app.use(service('/<%= name %>s', new <%= h.changeCase.pascal(name) %>Service()))

_templates/service/new/service-test.ejs.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
to: tests/services/<%= name %>s/get.test.ts
2+
to: tests/services/<%= name %>/get.test.ts
33
---
44
import { EntityManager } from '@mikro-orm/core'
55
import Koa from 'koa'
@@ -11,7 +11,7 @@ import UserFactory from '../../fixtures/UserFactory'
1111

1212
const baseUrl = '/<%= name %>s'
1313

14-
describe('<%= h.changeCase.sentenceCase(name) %>s service - get', () => {
14+
describe('<%= h.changeCase.sentenceCase(name) %> service - get', () => {
1515
let app: Koa
1616
let user: User
1717
let token: string

0 commit comments

Comments
 (0)