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

feat: api modelling base #1

Merged
merged 1 commit into from
Nov 8, 2023
Merged
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
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
testEnvironment: 'node'
};
2 changes: 1 addition & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"watch": ["src"],
"ext": "ts",
"exec": "node --inspect -r ts-node/register ./src/server.ts"
}
}
4 changes: 2 additions & 2 deletions readme-typescript-nodejs.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typescript-nodejs
# typescript-nodejs

Requirements: node.js >= 18.15.0 ( LTS )

Expand All @@ -14,4 +14,4 @@ Template for TypeScript nodejs projects. It includes:

1. Update package.json with your project details
2. Install dependencies with `npm install`
3. Start coding!
3. Start coding!
8 changes: 6 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export interface HealthcheckOptions {
title: string;
}

const healthcheck: FastifyPluginCallback<HealthcheckOptions> = (fastify, opts, next) => {
const healthcheck: FastifyPluginCallback<HealthcheckOptions> = (
fastify,
opts,
next
) => {
fastify.get<{ Reply: Static<typeof HelloWorld> }>(
'/',
{
Expand Down Expand Up @@ -62,4 +66,4 @@ export default (opts: ApiOptions) => {
// register other API routes here

return api;
}
};
123 changes: 123 additions & 0 deletions src/api_productions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { Type } from '@sinclair/typebox';
import { FastifyPluginCallback, FastifyRequest } from 'fastify';

Check warning on line 2 in src/api_productions.ts

View workflow job for this annotation

GitHub Actions / lint

'FastifyRequest' is defined but never used
import { NewProduction, Production, SdpOffer, SdpAnswer } from './models';

const apiProductions: FastifyPluginCallback = (fastify, opts, next) => {

Check warning on line 5 in src/api_productions.ts

View workflow job for this annotation

GitHub Actions / lint

'apiProductions' is assigned a value but never used
fastify.post<{
Body: typeof NewProduction;
Reply: typeof Production;
}>(
'/production',
{
schema: {
description: 'Create a new Production resource.',
body: NewProduction,
response: {
200: Production
}
}
},
async (request, reply) => {

Check warning on line 20 in src/api_productions.ts

View workflow job for this annotation

GitHub Actions / lint

'request' is defined but never used

Check warning on line 20 in src/api_productions.ts

View workflow job for this annotation

GitHub Actions / lint

'reply' is defined but never used
try {
//prod = new Production(name, [line1, line2, line3])
//Production construction will make calls to smb and set up each line.
} catch (err) {
//error handling
}
}
);

fastify.get<{
Params: { id: string };
Reply: any;

Check warning on line 32 in src/api_productions.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
}>(
'/production',
{
schema: {
description: 'Retrieves all Production resource.',
response: {
200: Type.Array(Production)
}
}
},
async (request, reply) => {

Check warning on line 43 in src/api_productions.ts

View workflow job for this annotation

GitHub Actions / lint

'request' is defined but never used

Check warning on line 43 in src/api_productions.ts

View workflow job for this annotation

GitHub Actions / lint

'reply' is defined but never used
try {
//request logic
} catch (err) {
//error handling
}
}
);

fastify.get<{
Params: { id: string };
Reply: any;

Check warning on line 54 in src/api_productions.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
}>(
'/productions/:id',
{
schema: {
description: 'Retrieves a Production resource.',
response: {
200: Production
}
}
},
async (request, reply) => {

Check warning on line 65 in src/api_productions.ts

View workflow job for this annotation

GitHub Actions / lint

'request' is defined but never used

Check warning on line 65 in src/api_productions.ts

View workflow job for this annotation

GitHub Actions / lint

'reply' is defined but never used
try {
//request logic
} catch (err) {
//error handling
}
}
);

fastify.delete<{
Params: { id: string };
Reply: string;
}>(
'/productions/:id',
{
schema: {
description: 'Delete a Production resource.',
response: {
200: Type.Object({
message: Type.Literal('removed')
})
}
}
},
async (request, reply) => {
try {
//request logic
} catch (err) {
//error handling
}
}
);

fastify.post<{
Params: { id: string; name: string };
Body: typeof SdpOffer;
Reply: typeof SdpAnswer;
}>(
'/productions/:id/lines/:name',
{
schema: {
description: 'Join a Production line.',
body: SdpOffer,
response: {
200: SdpAnswer
}
}
},
async (request, reply) => {
try {
//Generate SDP, and anything other information required to set up a connection.
} catch (err) {
//error handling
}
}
);

next();
};
Loading