@ -0,0 +1 @@ |
|||||
|
DATABASE_URL=mongodb://192.168.0.108/weather |
||||
@ -0,0 +1,25 @@ |
|||||
|
module.exports = { |
||||
|
parser: '@typescript-eslint/parser', |
||||
|
parserOptions: { |
||||
|
project: 'tsconfig.json', |
||||
|
tsconfigRootDir: __dirname, |
||||
|
sourceType: 'module', |
||||
|
}, |
||||
|
plugins: ['@typescript-eslint/eslint-plugin'], |
||||
|
extends: [ |
||||
|
'plugin:@typescript-eslint/recommended', |
||||
|
'plugin:prettier/recommended', |
||||
|
], |
||||
|
root: true, |
||||
|
env: { |
||||
|
node: true, |
||||
|
jest: true, |
||||
|
}, |
||||
|
ignorePatterns: ['.eslintrc.js'], |
||||
|
rules: { |
||||
|
'@typescript-eslint/interface-name-prefix': 'off', |
||||
|
'@typescript-eslint/explicit-function-return-type': 'off', |
||||
|
'@typescript-eslint/explicit-module-boundary-types': 'off', |
||||
|
'@typescript-eslint/no-explicit-any': 'off', |
||||
|
}, |
||||
|
}; |
||||
@ -0,0 +1,35 @@ |
|||||
|
# compiled output |
||||
|
/dist |
||||
|
/node_modules |
||||
|
|
||||
|
# Logs |
||||
|
logs |
||||
|
*.log |
||||
|
npm-debug.log* |
||||
|
pnpm-debug.log* |
||||
|
yarn-debug.log* |
||||
|
yarn-error.log* |
||||
|
lerna-debug.log* |
||||
|
|
||||
|
# OS |
||||
|
.DS_Store |
||||
|
|
||||
|
# Tests |
||||
|
/coverage |
||||
|
/.nyc_output |
||||
|
|
||||
|
# IDEs and editors |
||||
|
/.idea |
||||
|
.project |
||||
|
.classpath |
||||
|
.c9/ |
||||
|
*.launch |
||||
|
.settings/ |
||||
|
*.sublime-workspace |
||||
|
|
||||
|
# IDE - VSCode |
||||
|
.vscode/* |
||||
|
!.vscode/settings.json |
||||
|
!.vscode/tasks.json |
||||
|
!.vscode/launch.json |
||||
|
!.vscode/extensions.json |
||||
@ -0,0 +1,4 @@ |
|||||
|
{ |
||||
|
"singleQuote": true, |
||||
|
"trailingComma": "all" |
||||
|
} |
||||
@ -0,0 +1,73 @@ |
|||||
|
<p align="center"> |
||||
|
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a> |
||||
|
</p> |
||||
|
|
||||
|
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 |
||||
|
[circleci-url]: https://circleci.com/gh/nestjs/nest |
||||
|
|
||||
|
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p> |
||||
|
<p align="center"> |
||||
|
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a> |
||||
|
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a> |
||||
|
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a> |
||||
|
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a> |
||||
|
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a> |
||||
|
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a> |
||||
|
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a> |
||||
|
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a> |
||||
|
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a> |
||||
|
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a> |
||||
|
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a> |
||||
|
</p> |
||||
|
<!--[](https://opencollective.com/nest#backer) |
||||
|
[](https://opencollective.com/nest#sponsor)--> |
||||
|
|
||||
|
## Description |
||||
|
|
||||
|
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
```bash |
||||
|
$ npm install |
||||
|
``` |
||||
|
|
||||
|
## Running the app |
||||
|
|
||||
|
```bash |
||||
|
# development |
||||
|
$ npm run start |
||||
|
|
||||
|
# watch mode |
||||
|
$ npm run start:dev |
||||
|
|
||||
|
# production mode |
||||
|
$ npm run start:prod |
||||
|
``` |
||||
|
|
||||
|
## Test |
||||
|
|
||||
|
```bash |
||||
|
# unit tests |
||||
|
$ npm run test |
||||
|
|
||||
|
# e2e tests |
||||
|
$ npm run test:e2e |
||||
|
|
||||
|
# test coverage |
||||
|
$ npm run test:cov |
||||
|
``` |
||||
|
|
||||
|
## Support |
||||
|
|
||||
|
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). |
||||
|
|
||||
|
## Stay in touch |
||||
|
|
||||
|
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) |
||||
|
- Website - [https://nestjs.com](https://nestjs.com/) |
||||
|
- Twitter - [@nestframework](https://twitter.com/nestframework) |
||||
|
|
||||
|
## License |
||||
|
|
||||
|
Nest is [MIT licensed](LICENSE). |
||||
|
After Width: | Height: | Size: 7.7 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 7.1 KiB |
|
After Width: | Height: | Size: 9.6 KiB |
|
After Width: | Height: | Size: 9.5 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 6.7 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 9.4 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 8.0 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 8.9 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 9.4 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 8.7 KiB |
|
After Width: | Height: | Size: 6.8 KiB |
|
After Width: | Height: | Size: 9.5 KiB |
@ -0,0 +1,8 @@ |
|||||
|
{ |
||||
|
"$schema": "https://json.schemastore.org/nest-cli", |
||||
|
"collection": "@nestjs/schematics", |
||||
|
"sourceRoot": "src", |
||||
|
"compilerOptions": { |
||||
|
"deleteOutDir": true |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,78 @@ |
|||||
|
{ |
||||
|
"name": "weather-api", |
||||
|
"version": "0.0.1", |
||||
|
"description": "", |
||||
|
"author": "", |
||||
|
"private": true, |
||||
|
"license": "UNLICENSED", |
||||
|
"scripts": { |
||||
|
"build": "nest build", |
||||
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", |
||||
|
"start": "nest start", |
||||
|
"start:dev": "nest start --watch", |
||||
|
"start:debug": "nest start --debug --watch", |
||||
|
"start:prod": "node dist/main", |
||||
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", |
||||
|
"test": "jest", |
||||
|
"test:watch": "jest --watch", |
||||
|
"test:cov": "jest --coverage", |
||||
|
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", |
||||
|
"test:e2e": "jest --config ./test/jest-e2e.json" |
||||
|
}, |
||||
|
"dependencies": { |
||||
|
"@fastify/static": "^6.6.0", |
||||
|
"@forlagshuset/nestjs-mongoose-paginate": "^1.2.6", |
||||
|
"@nestjs/common": "^9.0.0", |
||||
|
"@nestjs/config": "^2.2.0", |
||||
|
"@nestjs/core": "^9.0.0", |
||||
|
"@nestjs/mapped-types": "*", |
||||
|
"@nestjs/mongoose": "^9.2.1", |
||||
|
"@nestjs/platform-express": "^9.0.0", |
||||
|
"@nestjs/platform-fastify": "^9.2.1", |
||||
|
"@nestjs/serve-static": "^3.0.0", |
||||
|
"@nestjs/websockets": "^9.2.1", |
||||
|
"mongoose": "^6.8.2", |
||||
|
"reflect-metadata": "^0.1.13", |
||||
|
"rxjs": "^7.2.0" |
||||
|
}, |
||||
|
"devDependencies": { |
||||
|
"@nestjs/cli": "^9.0.0", |
||||
|
"@nestjs/schematics": "^9.0.0", |
||||
|
"@nestjs/testing": "^9.0.0", |
||||
|
"@types/express": "^4.17.13", |
||||
|
"@types/jest": "29.2.4", |
||||
|
"@types/node": "18.11.18", |
||||
|
"@types/supertest": "^2.0.11", |
||||
|
"@typescript-eslint/eslint-plugin": "^5.0.0", |
||||
|
"@typescript-eslint/parser": "^5.0.0", |
||||
|
"eslint": "^8.0.1", |
||||
|
"eslint-config-prettier": "^8.3.0", |
||||
|
"eslint-plugin-prettier": "^4.0.0", |
||||
|
"jest": "29.3.1", |
||||
|
"prettier": "^2.3.2", |
||||
|
"source-map-support": "^0.5.20", |
||||
|
"supertest": "^6.1.3", |
||||
|
"ts-jest": "29.0.3", |
||||
|
"ts-loader": "^9.2.3", |
||||
|
"ts-node": "^10.0.0", |
||||
|
"tsconfig-paths": "4.1.1", |
||||
|
"typescript": "^4.7.4" |
||||
|
}, |
||||
|
"jest": { |
||||
|
"moduleFileExtensions": [ |
||||
|
"js", |
||||
|
"json", |
||||
|
"ts" |
||||
|
], |
||||
|
"rootDir": "src", |
||||
|
"testRegex": ".*\\.spec\\.ts$", |
||||
|
"transform": { |
||||
|
"^.+\\.(t|j)s$": "ts-jest" |
||||
|
}, |
||||
|
"collectCoverageFrom": [ |
||||
|
"**/*.(t|j)s" |
||||
|
], |
||||
|
"coverageDirectory": "../coverage", |
||||
|
"testEnvironment": "node" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
import { Test, TestingModule } from '@nestjs/testing'; |
||||
|
import { AppController } from './app.controller'; |
||||
|
import { AppService } from './app.service'; |
||||
|
|
||||
|
describe('AppController', () => { |
||||
|
let appController: AppController; |
||||
|
|
||||
|
beforeEach(async () => { |
||||
|
const app: TestingModule = await Test.createTestingModule({ |
||||
|
controllers: [AppController], |
||||
|
providers: [AppService], |
||||
|
}).compile(); |
||||
|
|
||||
|
appController = app.get<AppController>(AppController); |
||||
|
}); |
||||
|
|
||||
|
describe('root', () => { |
||||
|
it('should return "Hello World!"', () => { |
||||
|
expect(appController.getHello()).toBe('Hello World!'); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,12 @@ |
|||||
|
import { Controller, Get } from '@nestjs/common'; |
||||
|
import { AppService } from './app.service'; |
||||
|
|
||||
|
@Controller() |
||||
|
export class AppController { |
||||
|
constructor(private readonly appService: AppService) {} |
||||
|
|
||||
|
@Get() |
||||
|
getHello(): string { |
||||
|
return this.appService.getHello(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,31 @@ |
|||||
|
import { Module } from '@nestjs/common'; |
||||
|
import { AppController } from './app.controller'; |
||||
|
import { AppService } from './app.service'; |
||||
|
import { MongooseModule } from '@nestjs/mongoose'; |
||||
|
import { ConfigModule } from '@nestjs/config'; |
||||
|
import { WeatherModule } from './weather/weather.module'; |
||||
|
import { RouterModule } from '@nestjs/core'; |
||||
|
import { ServeStaticModule } from '@nestjs/serve-static'; |
||||
|
import { join } from 'path'; |
||||
|
import { NotificationModule } from './notification/notification.module'; |
||||
|
|
||||
|
@Module({ |
||||
|
imports: [ |
||||
|
ConfigModule.forRoot(), |
||||
|
MongooseModule.forRoot(process.env.DATABASE_URL), |
||||
|
ServeStaticModule.forRoot({ |
||||
|
rootPath: join(__dirname, '..', 'client'), |
||||
|
}), |
||||
|
WeatherModule, |
||||
|
RouterModule.register([ |
||||
|
{ |
||||
|
path: '/api/v1', |
||||
|
module: WeatherModule, |
||||
|
}, |
||||
|
]), |
||||
|
NotificationModule, |
||||
|
], |
||||
|
controllers: [AppController], |
||||
|
providers: [AppService], |
||||
|
}) |
||||
|
export class AppModule {} |
||||
@ -0,0 +1,8 @@ |
|||||
|
import { Injectable } from '@nestjs/common'; |
||||
|
|
||||
|
@Injectable() |
||||
|
export class AppService { |
||||
|
getHello(): string { |
||||
|
return 'Hello World!'; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
import { NestFactory } from '@nestjs/core'; |
||||
|
import { |
||||
|
FastifyAdapter, |
||||
|
NestFastifyApplication, |
||||
|
} from '@nestjs/platform-fastify'; |
||||
|
import { AppModule } from './app.module'; |
||||
|
|
||||
|
async function bootstrap() { |
||||
|
const app = await NestFactory.create<NestFastifyApplication>( |
||||
|
AppModule, |
||||
|
new FastifyAdapter({ logger: true }), |
||||
|
{ cors: true }, |
||||
|
); |
||||
|
await app.listen(3001); |
||||
|
} |
||||
|
bootstrap(); |
||||
@ -0,0 +1 @@ |
|||||
|
export class CreateNotificationDto {} |
||||
@ -0,0 +1,6 @@ |
|||||
|
import { PartialType } from '@nestjs/mapped-types'; |
||||
|
import { CreateNotificationDto } from './create-notification.dto'; |
||||
|
|
||||
|
export class UpdateNotificationDto extends PartialType(CreateNotificationDto) { |
||||
|
id: number; |
||||
|
} |
||||
@ -0,0 +1 @@ |
|||||
|
export class Notification {} |
||||
@ -0,0 +1,19 @@ |
|||||
|
import { Test, TestingModule } from '@nestjs/testing'; |
||||
|
import { NotificationGateway } from './notification.gateway'; |
||||
|
import { NotificationService } from './notification.service'; |
||||
|
|
||||
|
describe('NotificationGateway', () => { |
||||
|
let gateway: NotificationGateway; |
||||
|
|
||||
|
beforeEach(async () => { |
||||
|
const module: TestingModule = await Test.createTestingModule({ |
||||
|
providers: [NotificationGateway, NotificationService], |
||||
|
}).compile(); |
||||
|
|
||||
|
gateway = module.get<NotificationGateway>(NotificationGateway); |
||||
|
}); |
||||
|
|
||||
|
it('should be defined', () => { |
||||
|
expect(gateway).toBeDefined(); |
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,41 @@ |
|||||
|
import { |
||||
|
WebSocketGateway, |
||||
|
SubscribeMessage, |
||||
|
MessageBody, |
||||
|
} from '@nestjs/websockets'; |
||||
|
import { NotificationService } from './notification.service'; |
||||
|
import { CreateNotificationDto } from './dto/create-notification.dto'; |
||||
|
import { UpdateNotificationDto } from './dto/update-notification.dto'; |
||||
|
|
||||
|
@WebSocketGateway() |
||||
|
export class NotificationGateway { |
||||
|
constructor(private readonly notificationService: NotificationService) {} |
||||
|
|
||||
|
@SubscribeMessage('createNotification') |
||||
|
create(@MessageBody() createNotificationDto: CreateNotificationDto) { |
||||
|
return this.notificationService.create(createNotificationDto); |
||||
|
} |
||||
|
|
||||
|
@SubscribeMessage('findAllNotification') |
||||
|
findAll() { |
||||
|
return this.notificationService.findAll(); |
||||
|
} |
||||
|
|
||||
|
@SubscribeMessage('findOneNotification') |
||||
|
findOne(@MessageBody() id: number) { |
||||
|
return this.notificationService.findOne(id); |
||||
|
} |
||||
|
|
||||
|
@SubscribeMessage('updateNotification') |
||||
|
update(@MessageBody() updateNotificationDto: UpdateNotificationDto) { |
||||
|
return this.notificationService.update( |
||||
|
updateNotificationDto.id, |
||||
|
updateNotificationDto, |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
@SubscribeMessage('removeNotification') |
||||
|
remove(@MessageBody() id: number) { |
||||
|
return this.notificationService.remove(id); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
import { Module } from '@nestjs/common'; |
||||
|
import { NotificationService } from './notification.service'; |
||||
|
import { NotificationGateway } from './notification.gateway'; |
||||
|
|
||||
|
@Module({ |
||||
|
providers: [NotificationGateway, NotificationService] |
||||
|
}) |
||||
|
export class NotificationModule {} |
||||
@ -0,0 +1,18 @@ |
|||||
|
import { Test, TestingModule } from '@nestjs/testing'; |
||||
|
import { NotificationService } from './notification.service'; |
||||
|
|
||||
|
describe('NotificationService', () => { |
||||
|
let service: NotificationService; |
||||
|
|
||||
|
beforeEach(async () => { |
||||
|
const module: TestingModule = await Test.createTestingModule({ |
||||
|
providers: [NotificationService], |
||||
|
}).compile(); |
||||
|
|
||||
|
service = module.get<NotificationService>(NotificationService); |
||||
|
}); |
||||
|
|
||||
|
it('should be defined', () => { |
||||
|
expect(service).toBeDefined(); |
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,26 @@ |
|||||
|
import { Injectable } from '@nestjs/common'; |
||||
|
import { CreateNotificationDto } from './dto/create-notification.dto'; |
||||
|
import { UpdateNotificationDto } from './dto/update-notification.dto'; |
||||
|
|
||||
|
@Injectable() |
||||
|
export class NotificationService { |
||||
|
create(createNotificationDto: CreateNotificationDto) { |
||||
|
return 'This action adds a new notification'; |
||||
|
} |
||||
|
|
||||
|
findAll() { |
||||
|
return `This action returns all notification`; |
||||
|
} |
||||
|
|
||||
|
findOne(id: number) { |
||||
|
return `This action returns a #${id} notification`; |
||||
|
} |
||||
|
|
||||
|
update(id: number, updateNotificationDto: UpdateNotificationDto) { |
||||
|
return `This action updates a #${id} notification`; |
||||
|
} |
||||
|
|
||||
|
remove(id: number) { |
||||
|
return `This action removes a #${id} notification`; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1 @@ |
|||||
|
export class CreateWeatherDto {} |
||||
@ -0,0 +1,4 @@ |
|||||
|
import { PartialType } from '@nestjs/mapped-types'; |
||||
|
import { CreateWeatherDto } from './create-weather.dto'; |
||||
|
|
||||
|
export class UpdateWeatherDto extends PartialType(CreateWeatherDto) {} |
||||
@ -0,0 +1 @@ |
|||||
|
export class Weather {} |
||||
@ -0,0 +1,48 @@ |
|||||
|
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; |
||||
|
import { HydratedDocument } from 'mongoose'; |
||||
|
|
||||
|
export type WeatherDocument = HydratedDocument<Weather>; |
||||
|
|
||||
|
@Schema() |
||||
|
export class Weather { |
||||
|
@Prop() |
||||
|
deviceId: string; |
||||
|
|
||||
|
@Prop() |
||||
|
date: Date; |
||||
|
|
||||
|
@Prop() |
||||
|
summary: string; |
||||
|
|
||||
|
@Prop() |
||||
|
precipType: string; |
||||
|
|
||||
|
@Prop() |
||||
|
temperature: number; |
||||
|
|
||||
|
@Prop() |
||||
|
apparentTemperature: number; |
||||
|
|
||||
|
@Prop() |
||||
|
humidity: number; |
||||
|
|
||||
|
@Prop() |
||||
|
windSpeed: number; |
||||
|
|
||||
|
@Prop() |
||||
|
windBearing: number; |
||||
|
|
||||
|
@Prop() |
||||
|
visibility: number; |
||||
|
|
||||
|
@Prop() |
||||
|
loudCover: number; |
||||
|
|
||||
|
@Prop() |
||||
|
pressure: number; |
||||
|
|
||||
|
@Prop() |
||||
|
dailySummary: string; |
||||
|
} |
||||
|
|
||||
|
export const WeatherSchema = SchemaFactory.createForClass(Weather); |
||||
@ -0,0 +1,12 @@ |
|||||
|
import { |
||||
|
CollectionProperties, |
||||
|
Expose, |
||||
|
} from '@forlagshuset/nestjs-mongoose-paginate'; |
||||
|
|
||||
|
export class WeatherCollectionProperties extends CollectionProperties { |
||||
|
@Expose({ name: 'date', sortable: true }) |
||||
|
readonly date: 'asc' | 'desc'; |
||||
|
|
||||
|
@Expose({ name: 'deviceId', sortable: true }) |
||||
|
readonly deviceId: 'asc' | 'desc'; |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
import { Test, TestingModule } from '@nestjs/testing'; |
||||
|
import { WeatherController } from './weather.controller'; |
||||
|
import { WeatherService } from './weather.service'; |
||||
|
|
||||
|
describe('WeatherController', () => { |
||||
|
let controller: WeatherController; |
||||
|
|
||||
|
beforeEach(async () => { |
||||
|
const module: TestingModule = await Test.createTestingModule({ |
||||
|
controllers: [WeatherController], |
||||
|
providers: [WeatherService], |
||||
|
}).compile(); |
||||
|
|
||||
|
controller = module.get<WeatherController>(WeatherController); |
||||
|
}); |
||||
|
|
||||
|
it('should be defined', () => { |
||||
|
expect(controller).toBeDefined(); |
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,63 @@ |
|||||
|
import { |
||||
|
Controller, |
||||
|
Get, |
||||
|
Post, |
||||
|
Body, |
||||
|
Patch, |
||||
|
Param, |
||||
|
Delete, |
||||
|
Query, |
||||
|
} from '@nestjs/common'; |
||||
|
import { WeatherService } from './weather.service'; |
||||
|
import { CreateWeatherDto } from './dto/create-weather.dto'; |
||||
|
import { UpdateWeatherDto } from './dto/update-weather.dto'; |
||||
|
import { WeatherDocument } from './schemas/weather.schema'; |
||||
|
import { |
||||
|
CollectionDto, |
||||
|
CollectionResponse, |
||||
|
ValidationPipe, |
||||
|
} from '@forlagshuset/nestjs-mongoose-paginate'; |
||||
|
import { WeatherCollectionProperties } from './weather.collection-properties'; |
||||
|
|
||||
|
@Controller('weather') |
||||
|
export class WeatherController { |
||||
|
constructor(private readonly weatherService: WeatherService) {} |
||||
|
|
||||
|
@Post() |
||||
|
create(@Body() createWeatherDto: CreateWeatherDto) { |
||||
|
return this.weatherService.create(createWeatherDto); |
||||
|
} |
||||
|
|
||||
|
@Get() |
||||
|
findAll() { |
||||
|
return this.weatherService.findAll(); |
||||
|
} |
||||
|
|
||||
|
@Get('list') |
||||
|
async filter( |
||||
|
@Query(new ValidationPipe(WeatherCollectionProperties)) |
||||
|
collectionDto: CollectionDto, |
||||
|
): Promise<CollectionResponse<WeatherDocument>> { |
||||
|
return await this.weatherService.list(collectionDto); |
||||
|
} |
||||
|
|
||||
|
@Get(':id') |
||||
|
findOne(@Param('id') id: string) { |
||||
|
return this.weatherService.findOne(id); |
||||
|
} |
||||
|
|
||||
|
@Get('latest/:deviceId') |
||||
|
latest(@Param('deviceId') deviceId: string) { |
||||
|
return this.weatherService.latest(deviceId); |
||||
|
} |
||||
|
|
||||
|
@Patch(':id') |
||||
|
update(@Param('id') id: string, @Body() updateWeatherDto: UpdateWeatherDto) { |
||||
|
return this.weatherService.update(id, updateWeatherDto); |
||||
|
} |
||||
|
|
||||
|
@Delete(':id') |
||||
|
remove(@Param('id') id: string) { |
||||
|
return this.weatherService.remove(id); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
import { Module } from '@nestjs/common'; |
||||
|
import { WeatherService } from './weather.service'; |
||||
|
import { WeatherController } from './weather.controller'; |
||||
|
import { MongooseModule } from '@nestjs/mongoose'; |
||||
|
import { Weather, WeatherSchema } from './schemas/weather.schema'; |
||||
|
|
||||
|
@Module({ |
||||
|
imports: [ |
||||
|
MongooseModule.forFeature([{ name: Weather.name, schema: WeatherSchema }]), |
||||
|
], |
||||
|
controllers: [WeatherController], |
||||
|
providers: [WeatherService], |
||||
|
}) |
||||
|
export class WeatherModule {} |
||||
@ -0,0 +1,18 @@ |
|||||
|
import { Test, TestingModule } from '@nestjs/testing'; |
||||
|
import { WeatherService } from './weather.service'; |
||||
|
|
||||
|
describe('WeatherService', () => { |
||||
|
let service: WeatherService; |
||||
|
|
||||
|
beforeEach(async () => { |
||||
|
const module: TestingModule = await Test.createTestingModule({ |
||||
|
providers: [WeatherService], |
||||
|
}).compile(); |
||||
|
|
||||
|
service = module.get<WeatherService>(WeatherService); |
||||
|
}); |
||||
|
|
||||
|
it('should be defined', () => { |
||||
|
expect(service).toBeDefined(); |
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,51 @@ |
|||||
|
import { Injectable } from '@nestjs/common'; |
||||
|
import { CreateWeatherDto } from './dto/create-weather.dto'; |
||||
|
import { UpdateWeatherDto } from './dto/update-weather.dto'; |
||||
|
import { Weather, WeatherDocument } from './schemas/weather.schema'; |
||||
|
import { Model } from 'mongoose'; |
||||
|
import { InjectModel } from '@nestjs/mongoose'; |
||||
|
import { |
||||
|
CollectionDto, |
||||
|
CollectionResponse, |
||||
|
DocumentCollector, |
||||
|
} from '@forlagshuset/nestjs-mongoose-paginate'; |
||||
|
|
||||
|
@Injectable() |
||||
|
export class WeatherService { |
||||
|
constructor( |
||||
|
@InjectModel(Weather.name) private weatherModel: Model<WeatherDocument>, |
||||
|
) {} |
||||
|
create(createWeatherDto: CreateWeatherDto) { |
||||
|
const weatherModel = new this.weatherModel(createWeatherDto); |
||||
|
return weatherModel.save(); |
||||
|
} |
||||
|
|
||||
|
findAll() { |
||||
|
return this.weatherModel.find().exec(); |
||||
|
} |
||||
|
|
||||
|
async list( |
||||
|
collectionDto: CollectionDto, |
||||
|
): Promise<CollectionResponse<WeatherDocument>> { |
||||
|
const collector = new DocumentCollector<WeatherDocument>(this.weatherModel); |
||||
|
return collector.find(collectionDto); |
||||
|
} |
||||
|
|
||||
|
findOne(id: string) { |
||||
|
return this.weatherModel.findById(id).exec(); |
||||
|
} |
||||
|
|
||||
|
latest(deviceId: string) { |
||||
|
return this.weatherModel.findOne({ deviceId: deviceId }).exec(); |
||||
|
} |
||||
|
|
||||
|
async update(id: string, updateWeatherDto: UpdateWeatherDto) { |
||||
|
const weatherModel = await this.weatherModel.findById(id); |
||||
|
weatherModel.overwrite(updateWeatherDto); |
||||
|
return weatherModel.save(); |
||||
|
} |
||||
|
|
||||
|
remove(id: string) { |
||||
|
return this.weatherModel.findByIdAndRemove(id).exec(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,4 @@ |
|||||
|
{ |
||||
|
"extends": "./tsconfig.json", |
||||
|
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"] |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
{ |
||||
|
"compilerOptions": { |
||||
|
"module": "commonjs", |
||||
|
"declaration": true, |
||||
|
"removeComments": true, |
||||
|
"emitDecoratorMetadata": true, |
||||
|
"experimentalDecorators": true, |
||||
|
"allowSyntheticDefaultImports": true, |
||||
|
"target": "es2017", |
||||
|
"sourceMap": true, |
||||
|
"outDir": "./dist", |
||||
|
"baseUrl": "./", |
||||
|
"incremental": true, |
||||
|
"skipLibCheck": true, |
||||
|
"strictNullChecks": false, |
||||
|
"noImplicitAny": false, |
||||
|
"strictBindCallApply": false, |
||||
|
"forceConsistentCasingInFileNames": false, |
||||
|
"noFallthroughCasesInSwitch": false |
||||
|
} |
||||
|
} |
||||