Skip to content

Commit

Permalink
🐛 #147 add endpoint to get a user preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
JAGFx committed Nov 28, 2022
1 parent 178752e commit 0b7ca13
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export type UserPreferenceId = string;

export const enum UserPreferenceTarget {
Application = 'application',
Game = 'game'
Expand Down Expand Up @@ -27,4 +26,8 @@ export class UserPreferenceCollection extends Map<

return collection;
}

public toJson(): UserPreference[] {
return Array.from(this.values());
}
}
2 changes: 1 addition & 1 deletion lib/jagfx/server/src/user-preference/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export const toUserPreferencesCollection = (
});
}
);

return collection;
};
5 changes: 4 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ ci:
server\:dev\:build:
@bin/node npm run build -w servers/jagfx/dev

server\:dev\:watch:
@bin/server npm run watch -w servers/jagfx/dev

server\:dev\:start:
@bin/server npm run start -w servers/jagfx/dev
@bin/server npm start -w servers/jagfx/dev
4 changes: 2 additions & 2 deletions servers/jagfx/dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"type": "module",
"scripts": {
"build": "npx tsc -p tsconfig.json && tsc-alias",
"watch": "npm run build && npx concurrently -c 'tsc -w' 'tsc-alias -w' 'nodemon --experimental-specifier-resolution=node -w dist dist/index.js'",
"start": "nodemon -w src src/index.ts"
"watch": "nodemon -w src src/index.ts",
"start": "nodemon src/index.ts"
},
"ts-node": {
"esm": true
Expand Down
12 changes: 6 additions & 6 deletions servers/jagfx/dev/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import fastify from 'fastify';
import { UserPreference } from 'ets2-dashboard-core/src/configuration/user-preference/user-preference.type.js';

import configApplication from 'ets2-dashboard-server/src/config/config.json' assert { type: "json" };
import configApplication from 'ets2-dashboard-server/src/config/config.json' assert { type: 'json' };
import { toUserPreferencesCollection } from 'ets2-dashboard-server/src/user-preference/transformer.js';
import fastify from 'fastify';

// https://www.fastify.io/docs/latest/Reference/TypeScript/

const server = fastify();

server.get('/ping', async (request, reply) => {
server.get('/ping', async () => {
return 'pong +66';
});

server.get('/user-preferences', async (request, reply) => {
console.log( 'Plop' );
return toUserPreferencesCollection(configApplication);
server.get('/user-preferences', async (): Promise<UserPreference[]> => {
return toUserPreferencesCollection(configApplication).toJson();
});

server.listen({ port: 3000, host: '0.0.0.0' }, (err, address) => {
Expand Down

0 comments on commit 0b7ca13

Please sign in to comment.