Channel listing without db
This commit is contained in:
parent
836beda422
commit
0ea65a665d
1238
api/package-lock.json
generated
1238
api/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,13 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/node": "^22.13.10",
|
||||
"express": "^4.21.2",
|
||||
"node": "^23.9.0",
|
||||
"npm": "^11.2.0"
|
||||
"npm": "^11.2.0",
|
||||
"pg-promise": "^11.13.0",
|
||||
"ts-node": "^10.9.2",
|
||||
"tslib": "^2.8.1"
|
||||
},
|
||||
"name": "api",
|
||||
"version": "1.0.0",
|
||||
@ -13,7 +19,7 @@
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": "tsc",
|
||||
"debug": "node dist/main.js"
|
||||
"debug": "node dist/main.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
30
api/src/channels.ts
Normal file
30
api/src/channels.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { Request, Response } from 'express'
|
||||
import {values_present} from './common'
|
||||
|
||||
export enum Type {
|
||||
Text = 'text',
|
||||
Voice = 'voice',
|
||||
}
|
||||
|
||||
function valid_channel(ch: string) : boolean {
|
||||
return ch === Type.Text || ch === Type.Voice
|
||||
}
|
||||
|
||||
export async function list(req: Request, res: Response, db) : Promise<void> {
|
||||
const channels = await db.one('SELECT * from channels')
|
||||
res.send({path: req.path, data: channels.value})
|
||||
}
|
||||
|
||||
export async function create(req: Request, res: Response) : Promise<void> {
|
||||
const { name, description, type } = req.query
|
||||
if (values_present([name, description, type])|| !valid_channel(type.toString()) ) {
|
||||
res.status(400).send({ error: 'Invalid query string params' })
|
||||
return
|
||||
}
|
||||
res.send({
|
||||
id: 123,
|
||||
name: name,
|
||||
description: description,
|
||||
type: type
|
||||
})
|
||||
}
|
5
api/src/invites.ts
Normal file
5
api/src/invites.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { Request, Response } from 'express'
|
||||
|
||||
export async function code(req: Request, res: Response) : Promise<void> {
|
||||
res.send({path: req.path})
|
||||
}
|
@ -1 +1,22 @@
|
||||
console.log('asdf')
|
||||
import process from 'process'
|
||||
import express from 'express'
|
||||
import * as channels from './channels'
|
||||
import * as invites from './invites'
|
||||
const pgPromise = require('pg-promise')()
|
||||
|
||||
|
||||
const DB_URL = process.env['DB_CONNECTION_STRING']
|
||||
const PORT = process.env['PORT'] || 8000
|
||||
|
||||
console.log('db-url', DB_URL)
|
||||
console.log('port', PORT)
|
||||
|
||||
const app = express()
|
||||
const db = pgPromise(DB_URL)
|
||||
|
||||
|
||||
app.get('/invite/<code>', async (req, res) => await invites.code(req, res))
|
||||
app.get('/channels/list', async (req, res) => await channels.list(req, res, db))
|
||||
app.post('/channels/create', async (req, res) => await channels.create(req, res))
|
||||
|
||||
app.listen(PORT)
|
||||
|
Loading…
Reference in New Issue
Block a user