Skip to content

Commit 803530d

Browse files
committed
Using mongoose models, tests and lint settings.
1 parent 9314dd3 commit 803530d

File tree

12 files changed

+135
-47
lines changed

12 files changed

+135
-47
lines changed

.editorconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ indent_size = 2
99
end_of_line = lf
1010
charset = utf-8
1111
trim_trailing_whitespace = false
12-
insert_final_newline = false
12+
insert_final_newline = false
13+
prettier.singleQuote = true
14+
File renamed without changes.

.eslintrc.json

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
{
2-
"env": {
3-
"browser": true,
4-
"commonjs": true,
5-
"es2021": true
6-
},
7-
"extends": ["google"],
8-
"parser": "@typescript-eslint/parser",
9-
"parserOptions": {
10-
"ecmaVersion": 12
11-
},
12-
"plugins": ["@typescript-eslint"],
13-
"rules": {}
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:@typescript-eslint/recommended"
9+
],
10+
"parser": "@typescript-eslint/parser",
11+
"parserOptions": {
12+
"ecmaVersion": 12,
13+
"sourceType": "module"
14+
},
15+
"plugins": [
16+
"@typescript-eslint"
17+
],
18+
"rules": {
19+
}
1420
}

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"editor.formatOnSave": true
3-
}
2+
"editor.formatOnSave": true
3+
}

jest.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
// eslint-disable-next-line no-undef
12
module.exports = {
23
globals: {
34
"ts-jest": {
4-
tsConfig: "tsconfig.json",
5+
tsconfig: "tsconfig.json",
56
},
67
},
78
moduleFileExtensions: ["ts", "js"],
89
transform: {
910
"^.+\\.(ts|tsx)$": "ts-jest",
1011
},
11-
testMatch: ["**/test/**/*.test.(ts|js)"],
12+
testMatch: ["**/test/**/*.(test|spec).(ts|js)"],
1213
testEnvironment: "node",
1314
};

src/controllers/planes.controller.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { GET, Path, PathParam, POST, PUT } from "typescript-rest";
2+
import Plane, { PlaneModel } from "../models/plane.model";
3+
4+
@Path("api/planes/")
5+
export class PlanesController {
6+
@GET
7+
getAll(): Promise<Array<PlaneModel>> {
8+
return Plane.find().exec();
9+
}
10+
11+
@GET
12+
@Path(":name")
13+
getByName(@PathParam("name") name: string): Promise<Array<PlaneModel>> {
14+
return Plane.find({ name: name }).exec();
15+
}
16+
17+
@POST
18+
create(plane: PlaneModel): Promise<PlaneModel> {
19+
return Plane.create(plane);
20+
}
21+
22+
@PUT
23+
update(plane: PlaneModel): Promise<PlaneModel> {
24+
return Plane.replaceOne({ _id: plane.id }, plane).exec();
25+
}
26+
27+
delete(planeId: string): Promise<{ deletedCount?: number }> {
28+
return Plane.deleteOne({ _id: planeId }).exec();
29+
}
30+
}

src/models/plane.model.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import mongoose from "mongoose";
2+
3+
export interface PlaneModel {
4+
id?: any;
5+
manufacturer: string;
6+
name: string;
7+
maxRange: number;
8+
}
9+
10+
interface IPlane extends PlaneModel, mongoose.Document {}
11+
12+
export const PlaneSchema = new mongoose.Schema(
13+
{
14+
manufacturer: {
15+
required: true,
16+
type: String,
17+
},
18+
name: {
19+
required: true,
20+
type: String,
21+
},
22+
maxRange: {
23+
required: true,
24+
type: Number,
25+
default: 0,
26+
},
27+
},
28+
{ timestamps: true }
29+
);
30+
31+
const Plane: mongoose.Model<IPlane> = mongoose.model<IPlane>(
32+
"Plane",
33+
PlaneSchema
34+
);
35+
export default Plane;

src/start.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ export async function start(port?: number): Promise<ApiServer> {
2323
return apiServer;
2424
}
2525

26-
export function assertEnvironment() {
26+
export function assertEnvironment(): void {
2727
const errMessage = " variable not set";
2828

2929
if (!process.env.MONGODB_URI) {
3030
throw new Error("MONGODB_URI" + errMessage);
3131
}
32-
if (!process.env.JWT_SECRET) {
33-
throw new Error("JWT_SECRET" + errMessage);
34-
}
3532
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
describe("Planes controller", () => {
2+
// beforeAll(() => {});
3+
4+
it("get all", () => {
5+
expect(false).toBeTruthy();
6+
});
7+
8+
it("get by name", () => {
9+
expect(false).toBeTruthy();
10+
});
11+
12+
it("create", () => {
13+
expect(false).toBeTruthy();
14+
});
15+
16+
it("update", () => {
17+
expect(false).toBeTruthy();
18+
});
19+
});

test/hello.spec.ts

Whitespace-only changes.

tsconfig.base.json

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
{
2-
"compileOnSave": true,
3-
"compilerOptions": {
4-
"declaration": false,
5-
"experimentalDecorators": true,
6-
"emitDecoratorMetadata": true,
7-
"module": "commonjs",
8-
"newLine": "LF",
9-
"noFallthroughCasesInSwitch": true,
10-
"noImplicitAny": true,
11-
"noImplicitReturns": true,
12-
"noImplicitThis": false,
13-
"noUnusedParameters": false,
14-
"noUnusedLocals": true,
15-
"outDir": "dist",
16-
"skipLibCheck": true,
17-
"sourceMap": false,
18-
"strictNullChecks": false,
19-
"target": "es2016",
20-
"resolveJsonModule": true,
21-
"esModuleInterop": true,
22-
"rootDir": "src"
23-
}
2+
"compileOnSave": true,
3+
"compilerOptions": {
4+
"declaration": false,
5+
"experimentalDecorators": true,
6+
"emitDecoratorMetadata": true,
7+
"module": "commonjs",
8+
"newLine": "LF",
9+
"noFallthroughCasesInSwitch": true,
10+
"noImplicitAny": true,
11+
"noImplicitReturns": true,
12+
"noImplicitThis": false,
13+
"noUnusedParameters": false,
14+
"noUnusedLocals": true,
15+
"outDir": "dist",
16+
"skipLibCheck": true,
17+
"sourceMap": false,
18+
"strictNullChecks": false,
19+
"target": "es2016",
20+
"resolveJsonModule": true,
21+
"esModuleInterop": true,
22+
"rootDir": "src"
2423
}
25-
24+
}

tsconfig.build.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"extends": "./tsconfig.base.json",
3-
"include": ["src/**/*.ts"]
2+
"extends": "./tsconfig.base.json",
3+
"include": ["src/**/*.ts"]
44
}
5-

0 commit comments

Comments
 (0)