Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Channels #367

Merged
merged 15 commits into from
Dec 14, 2024
8 changes: 5 additions & 3 deletions _templates/service/new/service-test.ejs.t
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
---
to: tests/services/<%= name %>/index.test.ts
to: tests/services/<%= name %>/get.test.ts
---
import request from 'supertest'
import createUserAndToken from '../../utils/createUserAndToken'
import <%= h.changeCase.pascal(name) %>Factory from '../../fixtures/<%= h.changeCase.pascal(name) %>Factory'

describe('<%= h.changeCase.sentenceCase(name) %> service - index', () => {
describe('<%= h.changeCase.sentenceCase(name) %> service - get', () => {
it('should return a list of <%= h.changeCase.noCase(name) %>s', async () => {
const [token] = await createUserAndToken()
const <%= name %> = await new <%= h.changeCase.pascal(name) %>Factory().one()

await request(global.app)
.get('/<%= name %>s')
.get(`/<%= name %>/<%= name %>.id`)
.auth(token, { type: 'bearer' })
.expect(200)
})
Expand Down
5 changes: 1 addition & 4 deletions _templates/service/new/service.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import <%= h.changeCase.pascal(name) %> from '../entities/<%= name %>'
import <%= h.changeCase.pascal(name) %>Policy from '../policies/<%= name %>.policy'

export default class <%= h.changeCase.pascal(name) %>Service extends Service {
@Validate({
query: ['<%= h.changeCase.camel(name) %>Id']
})
@HasPermission(<%= h.changeCase.pascal(name) %>Policy, 'get')
async get(req: Request): Promise<Response> {
const { <%= h.changeCase.camel(name) %>Id } = req.query
const { <%= h.changeCase.camel(name) %>Id } = req.params
const em: EntityManager = req.ctx.em
const <%= h.changeCase.camel(name) %> = await em.getRepository(<%= h.changeCase.pascal(name) %>).findOne(Number(<%= h.changeCase.camel(name) %>Id))

Expand Down
14 changes: 0 additions & 14 deletions docker-compose.dev.yml

This file was deleted.

9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
services:
backend:
build:
context: .
target: dev
image: backend
ports:
- 3000:80
volumes:
- .env:/usr/backend/.env
- ./src:/usr/backend/src
- ./tests:/usr/backend/tests
depends_on:
- db
- redis
Expand Down Expand Up @@ -29,6 +37,7 @@ services:
build:
context: .
dockerfile: ./clickhouse/Dockerfile
image: clickhouse
environment:
CLICKHOUSE_USER: ${CLICKHOUSE_USER}
CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD}
Expand Down
2 changes: 1 addition & 1 deletion envs/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CLICKHOUSE_USER=gs_ch
CLICKHOUSE_PASSWORD=password
CLICKHOUSE_DB=gs_ch_dev

DEMO_ORGANISATION_NAME=Talo Demo
DEMO_ORGANISATION_NAME="Talo Demo"

SENDGRID_KEY=

Expand Down
62 changes: 61 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
"scripts": {
"watch": "tsx watch src/index.ts",
"build": "npx tsc -p tsconfig.build.json",
"dc": "docker compose -f docker-compose.yml -f docker-compose.dev.yml",
"seed": "DB_HOST=127.0.0.1 CLICKHOUSE_HOST=127.0.0.1 tsx tests/seed.ts",
"test": "./tests/run-tests.sh",
"up": "npm run dc -- up --build -d",
"down": "npm run dc -- down",
"restart": "npm run dc -- restart backend && npm run logs",
"logs": "npm run dc -- logs backend --follow",
"up": "docker compose up --build -d",
"down": "docker compose down",
"restart": "docker compose restart backend && npm run logs",
"logs": "docker compose logs backend --follow",
"migration:create": "DB_HOST=127.0.0.1 mikro-orm migration:create",
"migration:up": "DB_HOST=127.0.0.1 mikro-orm migration:up",
"service:create": "hygen service new",
Expand All @@ -30,6 +29,7 @@
"@types/lodash": "^4.14.182",
"@types/node": "20",
"@types/supertest": "^6.0.2",
"@types/ws": "^8.5.13",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"@vitest/coverage-v8": "^1.5.2",
Expand All @@ -40,6 +40,7 @@
"hygen": "^6.2.11",
"lint-staged": ">=10",
"supertest": "^7.0.0",
"superwstest": "^2.0.4",
"ts-node": "^10.7.0",
"tsx": "^4.11.0",
"typescript": "^5.4.5",
Expand Down Expand Up @@ -79,7 +80,9 @@
"qrcode": "^1.5.0",
"qs": "^6.11.0",
"stripe": "^12.0.0",
"uuid": "^9.0.0"
"uuid": "^9.0.0",
"ws": "^8.18.0",
"zod": "^3.23.8"
},
"mikro-orm": {
"configPaths": [
Expand Down
4 changes: 3 additions & 1 deletion src/config/api-routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Koa, { Context, Next } from 'koa'
import { service } from 'koa-clay'
import GameChannelAPIService from '../services/api/game-channel-api.service'
import HealthCheckAPIService from '../services/api/health-check-api.service'
import GameFeedbackAPIService from '../services/api/game-feedback-api.service'
import GameConfigAPIService from '../services/api/game-config-api.service'
Expand All @@ -17,7 +18,7 @@ import PlayerAuthAPIService from '../services/api/player-auth-api.service'
import continunityMiddleware from '../middlewares/continunity-middleware'
import PlayerGroupAPIService from '../services/api/player-group-api.service'

export default (app: Koa) => {
export default function configureAPIRoutes(app: Koa) {
app.use(apiKeyMiddleware)
app.use(apiRouteAuthMiddleware)
app.use(limiterMiddleware)
Expand All @@ -32,6 +33,7 @@ export default (app: Koa) => {
app.use(playerAuthMiddleware)
app.use(continunityMiddleware)

app.use(service('/v1/game-channels', new GameChannelAPIService()))
app.use(service('/v1/player-groups', new PlayerGroupAPIService()))
app.use(service('/v1/health-check', new HealthCheckAPIService()))
app.use(service('/v1/game-feedback', new GameFeedbackAPIService()))
Expand Down
4 changes: 3 additions & 1 deletion src/config/protected-routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Koa, { Context, Next } from 'koa'
import { service, ServiceOpts } from 'koa-clay'
import GameChannelService from '../services/game-channel.service'
import GameFeedbackService from '../services/game-feedback.service'
import PlayerGroupService from '../services/player-group.service'
import OrganisationService from '../services/organisation.service'
Expand All @@ -18,7 +19,7 @@ import BillingService from '../services/billing.service'
import IntegrationService from '../services/integration.service'
import { getRouteInfo, protectedRouteAuthMiddleware } from '../middlewares/route-middleware'

export default (app: Koa) => {
export default function protectedRoutes(app: Koa) {
app.use(protectedRouteAuthMiddleware)

app.use(async (ctx: Context, next: Next): Promise<void> => {
Expand Down Expand Up @@ -47,6 +48,7 @@ export default (app: Koa) => {
app.use(service('/games/:gameId/integrations', new IntegrationService(), serviceOpts))
app.use(service('/games/:gameId/player-groups', new PlayerGroupService(), serviceOpts))
app.use(service('/games/:gameId/game-feedback', new GameFeedbackService(), serviceOpts))
app.use(service('/games/:gameId/game-channels', new GameChannelService(), serviceOpts))
app.use(service('/games', new GameService(), serviceOpts))
app.use(service('/users', new UserService(), serviceOpts))
}
8 changes: 4 additions & 4 deletions src/config/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import * as Sentry from '@sentry/node'
import ormConfig from './mikro-orm.config'
import { MikroORM } from '@mikro-orm/mysql'
import tracingMiddleware from '../middlewares/tracing-middleware'
import createEmailQueue from '../lib/queues/createEmailQueue'

const initProviders = async (app: Koa) => {
export default async function initProviders(app: Koa, isTest: boolean) {
try {
const orm = await MikroORM.init(ormConfig)
app.context.em = orm.em

if (!app.context.isTest) {
if (!isTest) {
const migrator = orm.getMigrator()
await migrator.up()
}
Expand All @@ -20,6 +21,7 @@ const initProviders = async (app: Koa) => {
}

SendGrid.setApiKey(process.env.SENDGRID_KEY)
app.context.emailQueue = createEmailQueue()

Sentry.init({
dsn: process.env.SENTRY_DSN,
Expand All @@ -32,5 +34,3 @@ const initProviders = async (app: Koa) => {

app.use(tracingMiddleware)
}

export default initProviders
2 changes: 1 addition & 1 deletion src/config/public-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import InvitePublicService from '../services/public/invite-public.service'
import UserPublicService from '../services/public/user-public.service'
import WebhookService from '../services/public/webhook.service'

export default (app: Koa) => {
export default function configurePublicRoutes(app: Koa) {
const serviceOpts: ServiceOpts = {
docs: {
hidden: true
Expand Down
Loading
Loading