Skip to content

Commit

Permalink
Merge pull request #19 from hanriel/dev
Browse files Browse the repository at this point in the history
hotfix(#18): Cron task timezone
  • Loading branch information
hanriel authored Oct 4, 2023
2 parents 04cf05a + fd77e98 commit 77a297a
Show file tree
Hide file tree
Showing 9 changed files with 2,757 additions and 6,393 deletions.
8,905 changes: 2,548 additions & 6,357 deletions package-lock.json

Large diffs are not rendered by default.

36 changes: 2 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
"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"
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
},
"dependencies": {
"@nestjs/cli": "^10.0.0",
Expand All @@ -26,61 +21,34 @@
"@nestjs/core": "^10.0.0",
"@nestjs/jwt": "^10.1.0",
"@nestjs/mapped-types": "*",
"@types/multer": "^1.4.7",
"@nestjs/passport": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/schedule": "^3.0.4",
"@nestjs/swagger": "^7.1.2",
"@nestjs/typeorm": "^10.0.0",
"@types/express": "^4.17.17",
"@types/multer": "^1.4.7",
"axios": "^1.5.1",
"axios-cookiejar-support": "^4.0.7",
"mysql2": "^3.5.2",
"nestjs-telegraf": "^2.7.0",
"node-telegram-bot-api": "^0.63.0",
"passport": "^0.6.0",
"passport-local": "^1.0.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"telegraf": "^4.14.0",
"typeorm": "^0.3.17"
},
"devDependencies": {
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^5.59.11",
"@typescript-eslint/parser": "^5.59.11",
"eslint": "^8.42.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.5.0",
"prettier": "^2.8.8",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
5 changes: 4 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import { ConfigModule } from '@nestjs/config';
import { AuthModule } from './auth/auth.module';
import { ScheduleModule } from '@nestjs/schedule';
import { TelegramModule } from './telegram/telegram.module';
import { OrganizationsModule } from './organizations/organizations.module';
import { OrganizationEntity } from './organizations/entities/organization.entity';

@Module({
imports: [
Expand All @@ -44,14 +46,15 @@ import { TelegramModule } from './telegram/telegram.module';
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
entities: [UserEntity, FileEntity],
entities: [UserEntity, FileEntity, OrganizationEntity],
synchronize: true,
charset: 'utf8mb4',
}),
TelegramModule,
UsersModule,
FilesModule,
AuthModule,
OrganizationsModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
30 changes: 30 additions & 0 deletions src/organizations/dto/create-organization.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// EDUMGT-API
//
// Copyright (c) 2023 Fedoseev Danil (https://hanriel.ru)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import { ApiProperty } from '@nestjs/swagger';

export class CreateOrganizationDto {
@ApiProperty({
default: 'ГБПОУ ПМК',
})
short_name: string;
}
38 changes: 38 additions & 0 deletions src/organizations/entities/organization.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// EDUMGT-API
//
// Copyright (c) 2023 Fedoseev Danil (https://hanriel.ru)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';

@Entity('organizations')
export class OrganizationEntity {
@PrimaryGeneratedColumn()
id: number;

@Column()
email: string;

@Column()
full_name: string;

@Column()
short_name: string;
}
39 changes: 39 additions & 0 deletions src/organizations/organizations.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// EDUMGT-API
//
// Copyright (c) 2023 Fedoseev Danil (https://hanriel.ru)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import { Controller, Get, UseGuards } from "@nestjs/common";
import { ApiBearerAuth, ApiTags } from "@nestjs/swagger";
import { OrganizationsService } from "./organizations.service";
import { AuthGuard } from "@nestjs/passport";

@Controller('organizations')
@ApiTags('organizations')
@ApiBearerAuth()
export class OrganizationsController {
constructor(private readonly organizationsService: OrganizationsService) {}

@Get('org')
@UseGuards(AuthGuard)
getOrganizationById(id: number) {
return this.organizationsService.findById(id);
}
}
35 changes: 35 additions & 0 deletions src/organizations/organizations.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// EDUMGT-API
//
// Copyright (c) 2023 Fedoseev Danil (https://hanriel.ru)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import { Module } from '@nestjs/common';
import { OrganizationsService } from './organizations.service';
import { OrganizationsController } from './organizations.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { OrganizationEntity } from './entities/organization.entity';

@Module({
controllers: [OrganizationsController],
providers: [OrganizationsService],
imports: [TypeOrmModule.forFeature([OrganizationEntity])],
exports: [OrganizationsService],
})
export class OrganizationsModule {}
51 changes: 51 additions & 0 deletions src/organizations/organizations.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// EDUMGT-API
//
// Copyright (c) 2023 Fedoseev Danil (https://hanriel.ru)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import { Injectable } from '@nestjs/common';
import { CreateOrganizationDto } from './dto/create-organization.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { OrganizationEntity } from './entities/organization.entity';

@Injectable()
export class OrganizationsService {
constructor(
@InjectRepository(OrganizationEntity)
private repository: Repository<OrganizationEntity>,
) {}

async findByEmail(email: string) {
return this.repository.findOneBy({
email,
});
}

async findById(id: number) {
return this.repository.findOneBy({
id,
});
}

create(dto: CreateOrganizationDto) {
return this.repository.save(dto);
}
}
11 changes: 10 additions & 1 deletion src/telegram/telegram.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,20 @@ export class TelegramService {
console.log('Taksk Service constructor is started')
}

@Cron('0 45 7 * * 1-5')
@Cron('0 45 7 * * 1-5', {
timeZone: "Asia/Yekaterinburg"
})
handleCron() {
this.bot.telegram.sendMessage(process.env.ADMIN_TG_CHATID, 'Утреннее сообщение в 7:45');
}

@Cron('0 0 22 * * 1-5', {
timeZone: "Asia/Yekaterinburg"
})
handleCronEveneeng() {
this.bot.telegram.sendMessage(process.env.ADMIN_TG_CHATID, 'Вечернее сообщение в 22:00');
}

async getStartMessage(telgramId: number) {

let text: string
Expand Down

0 comments on commit 77a297a

Please sign in to comment.