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

fix: linting issues #237

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions libs/movex-server/src/lib/movex-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
} from 'movex-master';
import { delay, isOneOf } from './util';

const pkgVersion = require('../../package.json').version;

import { version as pkgVersion } from '../../package.json';
import { ResourceIdentifier } from 'movex-core-util';
const logsy = globalLogsy.withNamespace('[MovexServer]');

logsy.onLog((event) => {
Expand Down Expand Up @@ -144,22 +144,32 @@ export const movexServer = <TDefinition extends MovexDefinition>(
// });

app.get('/api/resources/:rid', async (req, res) => {
const rawRid = req.params.rid;
const rawRid = req.params.rid as ResourceIdentifier<
Extract<keyof TDefinition['resources'], string>
>;

if (!isResourceIdentifier(rawRid)) {
return res.sendStatus(400); // Bad Request
}

const ridObj = toResourceIdentifierObj(rawRid);

if (!isOneOf(ridObj.resourceType, objectKeys(definition.resources))) {
if (
!isOneOf(
ridObj.resourceType,
objectKeys(definition.resources) as Extract<
keyof TDefinition['resources'],
string
>[]
)
) {
return res.sendStatus(400); // Bad Request
}

res.header('Content-Type', 'application/json');

return store
.get(rawRid as any) // TODO: Not sure why this doesn't see it and needs to be casted to any?
.get(rawRid)
.map((data) => {
res.send(JSON.stringify(data, null, 4));
})
Expand Down Expand Up @@ -217,8 +227,6 @@ export const movexServer = <TDefinition extends MovexDefinition>(
// start the server
const port = process.env['port'] || 3333;
httpServer.listen(port, () => {
const address = httpServer.address();

// console.log(`[movex-server] v${pkgVersion} started at port ${port}.`);

// if (typeof address !== 'string') {
Expand Down
7 changes: 5 additions & 2 deletions libs/movex-server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
{
"path": "./tsconfig.spec.json"
}
]
}
],
"compilerOptions": {
"resolveJsonModule": true
}
}
Loading