fix and update

This commit is contained in:
lendry
2026-07-01 23:27:48 +03:00
parent 2b88e028c6
commit bcdfbc3861
36 changed files with 1504 additions and 320 deletions

View File

@@ -16,8 +16,9 @@ export class FamilyController {
private readonly jwt: JwtService
) {}
private async auth(authorization?: string) {
return getAuthorizedUserId(this.jwt, this.core, authorization);
private async auth(authorization?: string, passiveActivityHeader?: string) {
const touchActivity = passiveActivityHeader !== '1';
return getAuthorizedUserId(this.jwt, this.core, authorization, touchActivity);
}
@Post('groups')
@@ -33,8 +34,12 @@ export class FamilyController {
@Get('users/:userId/groups')
@ApiOperation({ summary: 'Список семей пользователя' })
async listGroups(@Headers('authorization') authorization: string | undefined, @Param('userId') userId: string) {
const requesterId = await this.auth(authorization);
async listGroups(
@Headers('authorization') authorization: string | undefined,
@Headers('x-id-passive-activity') passiveActivity: string | undefined,
@Param('userId') userId: string
) {
const requesterId = await this.auth(authorization, passiveActivity);
if (requesterId !== userId) {
throw new ForbiddenException('Можно просматривать только свои семьи');
}
@@ -50,8 +55,12 @@ export class FamilyController {
@Get('groups/:groupId')
@ApiOperation({ summary: 'Получить семейную группу' })
async getGroup(@Headers('authorization') authorization: string | undefined, @Param('groupId') groupId: string) {
const requesterId = await this.auth(authorization);
async getGroup(
@Headers('authorization') authorization: string | undefined,
@Headers('x-id-passive-activity') passiveActivity: string | undefined,
@Param('groupId') groupId: string
) {
const requesterId = await this.auth(authorization, passiveActivity);
return firstValueFrom(this.core.family.GetFamilyGroup({ requesterId, groupId }));
}
@@ -181,8 +190,12 @@ export class FamilyController {
@Get('groups/:groupId/presence')
@ApiOperation({ summary: 'Онлайн-статус участников семьи' })
async getPresence(@Headers('authorization') authorization: string | undefined, @Param('groupId') groupId: string) {
const requesterId = await this.auth(authorization);
async getPresence(
@Headers('authorization') authorization: string | undefined,
@Headers('x-id-passive-activity') passiveActivity: string | undefined,
@Param('groupId') groupId: string
) {
const requesterId = await this.auth(authorization, passiveActivity);
return firstValueFrom(this.core.family.GetFamilyPresence({ requesterId, groupId }));
}

View File

@@ -117,7 +117,7 @@ export class MediaController {
@Post('documents/:documentId/photo/upload-url')
@ApiBearerAuth()
@ApiOperation({ summary: 'Получить URL для фото документа', description: 'Presigned URL для загрузки скана/фото документа в MinIO.' })
@ApiOperation({ summary: 'Получить URL для файла документа', description: 'Presigned URL для загрузки скана, фото или файла документа в MinIO.' })
@ApiBody({ type: DocumentPhotoUploadDto })
async createDocumentPhotoUploadUrl(
@Headers('authorization') authorization: string | undefined,
@@ -125,22 +125,31 @@ export class MediaController {
@Body() dto: DocumentPhotoUploadDto
) {
const userId = await this.authUserId(authorization);
return firstValueFrom(this.core.media.CreateDocumentPhotoUploadUrl({ userId, documentId, contentType: dto.contentType }));
return firstValueFrom(
this.core.media.CreateDocumentPhotoUploadUrl({
userId,
documentId,
contentType: dto.contentType,
fileName: dto.fileName
})
);
}
@Get('users/:userId/documents/photo-url')
@ApiBearerAuth()
@ApiOperation({ summary: 'Получить ссылку на фото документа', description: 'Временная ссылка на просмотр фото документа (15 минут).' })
@ApiOperation({ summary: 'Получить ссылку на файл документа', description: 'Временная ссылка на просмотр файла документа (15 минут).' })
@ApiParam({ name: 'userId', description: 'ID владельца документа' })
@ApiQuery({ name: 'storageKey', description: 'Ключ объекта в MinIO' })
@ApiQuery({ name: 'fileName', required: false, description: 'Имя файла для скачивания' })
async getDocumentPhotoUrl(
@Headers('authorization') authorization: string | undefined,
@Param('userId') userId: string,
@Query('storageKey') storageKey: string
@Query('storageKey') storageKey: string,
@Query('fileName') fileName?: string
) {
const requesterId = await this.authUserId(authorization);
return firstValueFrom(
this.core.media.GetDocumentPhotoAccessUrl({ requesterId, targetUserId: userId, storageKey })
this.core.media.GetDocumentPhotoAccessUrl({ requesterId, targetUserId: userId, storageKey, fileName })
);
}

View File

@@ -40,8 +40,12 @@ export class NotificationsController {
@Get('unread-count')
@ApiOperation({ summary: 'Количество непрочитанных уведомлений' })
async unreadCount(@Headers('authorization') authorization: string | undefined) {
const userId = await getAuthorizedUserId(this.jwt, this.core, authorization);
async unreadCount(
@Headers('authorization') authorization: string | undefined,
@Headers('x-id-passive-activity') passiveActivity: string | undefined
) {
const touchActivity = passiveActivity !== '1';
const userId = await getAuthorizedUserId(this.jwt, this.core, authorization, touchActivity);
return firstValueFrom(this.core.notifications.GetUnreadCount({ userId }));
}