Browse Source

Merge branch 'files-configs' into 'stage'

Files configs

See merge request jetup/rws/api-rws!225
merge-requests/226/head
Coder 2 years ago
parent
commit
ae1d69738f
  1. 21
      .env.example
  2. 27
      src/config/index.ts
  3. 2
      src/core/namespaces/tasks.namespace.ts
  4. 4
      src/domain/tasks/services/tasks.service.ts
  5. 26
      src/rest/admin/tasks/services/admin-tasks.service.ts
  6. 26
      src/rest/app/tasks/services/app-tasks.service.ts
  7. 16
      src/rest/common/configs/configs.module.ts
  8. 23
      src/rest/common/configs/controllers/common-configs.controller.ts
  9. 3
      src/rest/common/configs/controllers/index.ts
  10. 32
      src/rest/common/configs/dtos/files-config.ts
  11. 1
      src/rest/common/configs/dtos/index.ts
  12. 10
      src/rest/common/configs/services/configs.service.ts
  13. 5
      src/rest/common/configs/services/index.ts
  14. 6
      src/rest/common/index.ts
  15. 2
      src/shared/consts/file-extensions.ts

21
.env.example

@ -56,4 +56,23 @@ PUSH_REST_API_KEY=MjI2MWEyYzctYzFhZC00YjQzLWE2NzUtYjg1ZDQ3NDcwODVh @@ -56,4 +56,23 @@ PUSH_REST_API_KEY=MjI2MWEyYzctYzFhZC00YjQzLWE2NzUtYjg1ZDQ3NDcwODVh
# SYSTEM_USERS
SYSTEMS_USERS_PHONES='380111111111,380222222222'
RWS_EMAIL=TaskMe@rwsbank.com.ua
RWS_EMAIL=TaskMe@rwsbank.com.ua
# FILES LIMITS
# IN PX
ALLOWED_AVATAR_WIDTH=200
# IN PX
ALLOWED_AVATAR_HEIGHT=200
# IN KB
ALLOWED_AVATAR_SIZE=500
# ONLY IMAGE FILES TYPES DIVIDED BY COMMA
ALLOWED_AVATAR_TYPES='jpg,svg,png,webp'
# IN KB
ALLOWED_TASK_FILES_SIZE=100000
# ANY FILES TYPES DIVIDED BY COMMA
ALLOWED_TASK_FILES_TYPES='jpeg,jpg,png,svg,webp,tiff,pdf,txt,doc,docx,xls,xlsx'
# IN KB
ALLOWED_CHAT_FILES_SIZE=50000
# IN KB
ALLOWED_CHAT_VIDEOS_SIZE=100000

27
src/config/index.ts

@ -91,6 +91,32 @@ const getEmail = () => { @@ -91,6 +91,32 @@ const getEmail = () => {
return getEnv('RWS_EMAIL')
}
const envKeyByLimitName = {
avatarWidth: 'ALLOWED_AVATAR_WIDTH',
avatarHeight: 'ALLOWED_AVATAR_HEIGHT',
avatarSize: 'ALLOWED_AVATAR_SIZE',
avatarTypes: 'ALLOWED_AVATAR_TYPES',
taskFilesSize: 'ALLOWED_TASK_FILES_SIZE',
taskFilesTypes: 'ALLOWED_TASK_FILES_TYPES',
chatFilesSize: 'ALLOWED_CHAT_FILES_SIZE',
chatVideosSize: 'ALLOWED_CHAT_VIDEOS_SIZE',
}
const getFilesLimitsConfig = () => {
const config = {}
for (const key of Object.keys(envKeyByLimitName)) {
try {
const limitValue = getEnv(envKeyByLimitName[key])
if (limitValue) config[key] = limitValue
} catch (e) {
console.log('Error on get files limits config', e)
}
}
return config
}
export const $config = {
getDatabaseConfig,
getJwtConfig,
@ -101,4 +127,5 @@ export const $config = { @@ -101,4 +127,5 @@ export const $config = {
getLinkToWeb,
getOldDatabaseConfig,
getEmail,
getFilesLimitsConfig,
}

2
src/core/namespaces/tasks.namespace.ts

@ -329,7 +329,7 @@ export namespace Tasks { @@ -329,7 +329,7 @@ export namespace Tasks {
id: number,
userId: number,
executorsIds: number[],
): Promise<Record<number, number>>
): Promise<{ newTasksIds: Record<number, number>; newTasks: TaskModel[] }>
/**
* Видаляє завдання

4
src/domain/tasks/services/tasks.service.ts

@ -254,6 +254,7 @@ export class TasksService implements Tasks.ITasksService { @@ -254,6 +254,7 @@ export class TasksService implements Tasks.ITasksService {
}
const newTasksIds: Record<number, number> = {}
const newTasks = []
await Promise.all(
executorsIds.map(async it => {
@ -261,6 +262,7 @@ export class TasksService implements Tasks.ITasksService { @@ -261,6 +262,7 @@ export class TasksService implements Tasks.ITasksService {
const newTask = await this.tasksRepository.save(dataToSave)
newTasksIds[it] = newTask.id
newTasks.push(newTask)
await this.copyTaskFiles(newTask.id, id)
@ -284,7 +286,7 @@ export class TasksService implements Tasks.ITasksService { @@ -284,7 +286,7 @@ export class TasksService implements Tasks.ITasksService {
await this.deleteTask(id, userId)
return newTasksIds
return { newTasksIds, newTasks }
}
public async deleteTask(id: number, userId: number) {

26
src/rest/admin/tasks/services/admin-tasks.service.ts

@ -60,7 +60,7 @@ export class AdminTasksService { @@ -60,7 +60,7 @@ export class AdminTasksService {
})
try {
await this.sendNewTaskEmail(id, task)
await this.sendNewTaskEmail(task)
} catch (e) {
console.log('Error send email to executor', e)
}
@ -71,8 +71,8 @@ export class AdminTasksService { @@ -71,8 +71,8 @@ export class AdminTasksService {
return newTaskIds
}
private async sendNewTaskEmail(userId: number, task: Tasks.TaskModel) {
const user = await this.usersService.getOne(userId)
private async sendNewTaskEmail(task: Tasks.TaskModel) {
const user = await this.usersService.getOne(task.executorId)
const author = await this.usersService.getOne(task.authorId, ['info'])
const params = {
@ -212,13 +212,29 @@ export class AdminTasksService { @@ -212,13 +212,29 @@ export class AdminTasksService {
const result: Record<number, Record<number, number>> = {}
for await (const id of dto.tasksIds) {
const tasksIds = await this.tasksService.reassign(id, userId, dto.executorsIds)
result[id] = tasksIds
const { newTasksIds, newTasks } = await this.tasksService.reassign(
id,
userId,
dto.executorsIds,
)
result[id] = newTasksIds
this.informExecutors(newTasks)
}
return { result }
}
private async informExecutors(tasks: Tasks.TaskModel[]) {
for (const task of tasks) {
try {
await this.sendNewTaskEmail(task)
} catch (e) {
console.log('Send email to executor failed', e)
}
}
}
private async prepareParams(dto: FilterTasksParamsDto, userId: number) {
if (!dto) return {}
const params: Tasks.IGetTasksListParams = {

26
src/rest/app/tasks/services/app-tasks.service.ts

@ -90,7 +90,7 @@ export class AppTasksService { @@ -90,7 +90,7 @@ export class AppTasksService {
const task = await this.tasksService.saveTask(dataToSave as Tasks.SaveTaskPayload)
try {
await this.sendNewTaskEmail(Number(id), task)
await this.sendNewTaskEmail(task)
} catch (e) {
console.log('Send email to executor failed', e)
}
@ -101,8 +101,8 @@ export class AppTasksService { @@ -101,8 +101,8 @@ export class AppTasksService {
return newTaskIds
}
private async sendNewTaskEmail(userId: number, task: Tasks.TaskModel) {
const user = await this.usersService.getOne(userId)
private async sendNewTaskEmail(task: Tasks.TaskModel) {
const user = await this.usersService.getOne(task.executorId)
const author = await this.usersService.getOne(task.authorId, ['info'])
const params = {
@ -369,13 +369,29 @@ export class AppTasksService { @@ -369,13 +369,29 @@ export class AppTasksService {
const result: Record<number, Record<number, number>> = {}
for await (const id of dto.tasksIds) {
const tasksIds = await this.tasksService.reassign(id, userId, dto.executorsIds)
result[id] = tasksIds
const { newTasksIds, newTasks } = await this.tasksService.reassign(
id,
userId,
dto.executorsIds,
)
result[id] = newTasksIds
this.informExecutors(newTasks)
}
return { result }
}
private async informExecutors(tasks: Tasks.TaskModel[]) {
for (const task of tasks) {
try {
await this.sendNewTaskEmail(task)
} catch (e) {
console.log('Send email to executor failed', e)
}
}
}
public async delete(id: string, userId: number) {
let taskId: number
if (!_.isNaN(Number(id))) taskId = Number(id)

16
src/rest/common/configs/configs.module.ts

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
import { DynamicModule, Module } from '@nestjs/common'
import { JwtModule } from 'src/libs'
import { COMMON_CONFIGS_CONTROLLERS } from './controllers'
import { COMMON_CONFIGS_SERVICES } from './services'
@Module({})
export class CommonConfigsModule {
static forRoot(): DynamicModule {
return {
module: CommonConfigsModule,
imports: [JwtModule.forFeature()],
controllers: COMMON_CONFIGS_CONTROLLERS,
providers: COMMON_CONFIGS_SERVICES,
}
}
}

23
src/rest/common/configs/controllers/common-configs.controller.ts

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
import { Controller, Get } from '@nestjs/common'
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger'
import { AuthGuard } from 'src/domain/sessions/decorators'
import { FilesLimitsConfigDto } from '../dtos'
import { CommonConfigsService } from '../services'
@ApiTags('Common | Configs')
@Controller('common/configs')
export class CommonConfigsController {
constructor(private configsService: CommonConfigsService) {}
@ApiOperation({ summary: 'Отримання параметрів конфігурації для файлів' })
@ApiOkResponse({
status: 200,
description: 'Повертає параметри конфігурації',
type: FilesLimitsConfigDto,
})
@AuthGuard()
@Get('files-config')
public async getFilesConfig() {
return this.configsService.getFilesLimitsConfig()
}
}

3
src/rest/common/configs/controllers/index.ts

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
import { CommonConfigsController } from './common-configs.controller'
export const COMMON_CONFIGS_CONTROLLERS = [CommonConfigsController]

32
src/rest/common/configs/dtos/files-config.ts

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
import { DtoProperty, DtoPropertyOptional } from 'src/shared'
export class FilesParametersDto {
@DtoPropertyOptional()
avatarWidth: string
@DtoPropertyOptional()
avatarHeight: string
@DtoPropertyOptional()
avatarSize: string
@DtoPropertyOptional()
avatarTypes: string
@DtoPropertyOptional()
taskFilesSize: string
@DtoPropertyOptional()
taskFilesTypes: string
@DtoPropertyOptional()
chatFilesSize: string
@DtoPropertyOptional()
chatVideosSize: string
}
export class FilesLimitsConfigDto {
@DtoProperty({ type: FilesParametersDto })
config: FilesParametersDto
}

1
src/rest/common/configs/dtos/index.ts

@ -0,0 +1 @@ @@ -0,0 +1 @@
export * from './files-config'

10
src/rest/common/configs/services/configs.service.ts

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
import { Injectable } from '@nestjs/common'
import { $config } from 'src/config'
@Injectable()
export class CommonConfigsService {
public getFilesLimitsConfig() {
const config = $config.getFilesLimitsConfig()
return { config }
}
}

5
src/rest/common/configs/services/index.ts

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
import { CommonConfigsService } from './configs.service'
export const COMMON_CONFIGS_SERVICES = [CommonConfigsService]
export { CommonConfigsService }

6
src/rest/common/index.ts

@ -1,3 +1,7 @@ @@ -1,3 +1,7 @@
import { CommonChatsModule } from './chats/chats.module'
import { CommonConfigsModule } from './configs/configs.module'
export const getRestCommonModules = () => [CommonChatsModule.forRoot()]
export const getRestCommonModules = () => [
CommonChatsModule.forRoot(),
CommonConfigsModule.forRoot(),
]

2
src/shared/consts/file-extensions.ts

@ -3,7 +3,7 @@ export const UPLOAD_IMAGE_FILE_TYPES = [ @@ -3,7 +3,7 @@ export const UPLOAD_IMAGE_FILE_TYPES = [
'jpg',
'jpeg',
'png',
// 'svg',
'svg',
// 'gif',
// 'tif',
// 'tiff',

Loading…
Cancel
Save