1
0
mirror of https://github.com/tcgdex/cards-database.git synced 2025-04-22 02:42:09 +00:00
Florian Bouillon c4b4449fd4
feature: Implement new Server infrastructure with GraphQL. (#132)
* Added new compiler to db

Signed-off-by: Avior <florian.bouillon@delta-wings.net>

* Add compiled DB to artifacts

Signed-off-by: Avior <florian.bouillon@delta-wings.net>

* Fixed space error

Signed-off-by: Avior <florian.bouillon@delta-wings.net>

* Fixed?

Signed-off-by: Avior <florian.bouillon@delta-wings.net>

* Update node.js.yml

* Update node.js.yml

* Made change so the db is no longer dependent on the SDK

Signed-off-by: Avior <florian.bouillon@delta-wings.net>

* f

Signed-off-by: Avior <florian.bouillon@delta-wings.net>

* Fixed artifact

Signed-off-by: Avior <florian.bouillon@delta-wings.net>

* U

Signed-off-by: Avior <florian.bouillon@delta-wings.net>

* \Changed folder

Signed-off-by: Avior <florian.bouillon@delta-wings.net>

* Fixede?

Signed-off-by: Avior <florian.bouillon@delta-wings.net>

* Try with everything

* saved the file ;)

* ignore compiler

* Fixed prebuild being run again

* Fixed public folder

Signed-off-by: Avior <github@avior.me>

* fixed graphql file

Signed-off-by: Avior <github@avior.me>

* fixed?

Signed-off-by: Avior <github@avior.me>

* Check tree because life is potato

Signed-off-by: Avior <github@avior.me>

* this is harder

Signed-off-by: Avior <github@avior.me>

* f

Signed-off-by: Avior <github@avior.me>

* Fixed?

Signed-off-by: Avior <github@avior.me>

* r

Signed-off-by: Avior <github@avior.me>

* fd

Signed-off-by: Avior <github@avior.me>

* added back context

Signed-off-by: Avior <github@avior.me>

* ah

Signed-off-by: Avior <github@avior.me>

* AAH

Signed-off-by: Avior <github@avior.me>

* AAAH

Signed-off-by: Avior <github@avior.me>

* ffffffffffffffffff

Signed-off-by: Avior <github@avior.me>

* fix: Changed the default builder

Signed-off-by: Avior <github@avior.me>

* Removed useless tree function

Signed-off-by: Avior <github@avior.me>
2021-11-04 10:02:26 +01:00

58 lines
1.4 KiB
TypeScript

import { SupportedLanguages } from '@tcgdex/sdk'
import { Response } from 'express'
import fs from 'fs'
export function checkLanguage(str: string): str is SupportedLanguages {
return ['en', 'fr', 'es', 'it', 'pt', 'de'].includes(str)
}
export function unique(arr: Array<string>): Array<string> {
return arr.reduce((p, c) => p.includes(c) ? p : [...p, c], [] as Array<string>)
}
export function sendError(error: 'UnknownError' | 'NotFoundError' | 'LanguageNotFoundError' | 'EndpointNotFoundError', res: Response, v?: any) {
let message = ''
let status = 404
switch (error) {
case 'LanguageNotFoundError':
message = `Language not found (${v})`
break
case 'EndpointNotFoundError':
message = `Endpoint not found (${v})`
break
case 'NotFoundError':
message = 'The resource you are searching does not exists'
break
case 'UnknownError':
default:
message = `an unknown error occured (${v})`
status = 500
break
}
res.status(status).json({
message
}).end()
}
export function betterSorter(a: string, b: string) {
const ra = parseInt(a, 10)
const rb = parseInt(b, 10)
if (!isNaN(ra) && !isNaN(rb)) {
return ra - rb
}
return a >= b ? 1 : -1
}
export function tree(path: string, padding = 0) {
const folder = fs.readdirSync(path)
for (const file of folder) {
const filePath = path + '/' + file
console.log(filePath.padStart(padding, '-'))
try {
fs.lstatSync(filePath).isDirectory()
tree(filePath)
} catch {}
}
}