Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
📦 (openapi) Adding Generated Code
Browse files Browse the repository at this point in the history
HospitalRun/hospitalrun#15 HospitalRun/hospitalrun#13 #155
  • Loading branch information
PhearZero committed Sep 12, 2019
1 parent 2ae2c68 commit 5fe2a3e
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.data
# Logs
logs
*.log
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"devDependencies": {
"@commitlint/cli": "^8.1.0",
"@commitlint/core": "^8.1.0",
"@hospitalrun-org/core": "1.0.0",
"@semantic-release/changelog": "^3.0.4",
"@semantic-release/git": "^7.0.16",
"@semantic-release/github": "^5.4.3",
Expand Down
31 changes: 31 additions & 0 deletions src/plugins/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fp from 'fastify-plugin'
import { UserService, User } from '@hospitalrun-org/core'

export default fp((fastify, opts, next) => {
const userService = new UserService(opts)
/**
* @param {Object} options
* @throws {Error}
* @return {Promise}
*/
fastify.decorate('findUser', (user: User) => {
return userService.findUser(user)
})
/**
* @param {Object} options
* @param {String} options.id ID of an Document to Get
* @throws {Error}
* @return {Promise}
*/
fastify.decorate('findUserById', (user: User) => {
return userService.findUserById(user)
})
next()
})

declare module 'fastify' {
interface FastifyInstance {
findUser(): User
findUserById(): User
}
}
48 changes: 48 additions & 0 deletions src/services/routes/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Server, IncomingMessage, ServerResponse } from 'http'
import { FastifyInstance } from 'fastify'
import { nextCallback } from 'fastify-plugin'

export default(
fastify: FastifyInstance<Server, IncomingMessage, ServerResponse>,
opts: {},
next: nextCallback,
) => {

/**
* Search for a User in the Database
*/
fastify.get('/', async (request, reply) => {
const options = {
};
console.log(options)
try {
const result = await fastify.findUser();
reply.code(200).send(result);
} catch (err) {
reply.code(500).send({
status: 500,
error: 'Server Error'
});
}
});
/**
* Search for a User in the Database
*/
fastify.get('/:id', async (request, reply) => {
const options = {
id: request.params['id']
};
console.log(options)
try {
const result = await fastify.findUserById();
reply.code(200).send(result);
} catch (err) {
reply.code(500).send({
status: 500,
error: 'Server Error'
});
}
});
next()
}
export const autoPrefix = '/user'

0 comments on commit 5fe2a3e

Please sign in to comment.