@kenniy/godeye-data-contracts
Version:
Enterprise-grade base repository architecture for GOD-EYE microservices with zero overhead and maximum code reuse
86 lines (85 loc) • 3.69 kB
JavaScript
;
/**
* File-specific Query DTO
* Extends base with File entity fields and relations
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileQueryDto = void 0;
const class_validator_1 = require("class-validator");
const class_transformer_1 = require("class-transformer");
const swagger_1 = require("@nestjs/swagger");
const base_query_dto_1 = require("./base-query.dto");
class FileQueryDto extends base_query_dto_1.BaseQueryDto {
/**
* Define File entity relations for smart include parsing
*/
getKnownRelations() {
return ['user', 'folder', 'tags', 'metadata', 'createdBy', 'updatedBy'];
}
buildWhereClause() {
const where = super.buildWhereClause() || {};
if (this.userId)
where.userId = this.userId;
if (this.fileType)
where.fileType = this.fileType;
if (this.mimeType)
where.mimeType = this.mimeType;
// Size range
if (this.minSize || this.maxSize) {
where.size = {};
if (this.minSize)
where.size.$gte = this.minSize;
if (this.maxSize)
where.size.$lte = this.maxSize;
}
return where;
}
}
exports.FileQueryDto = FileQueryDto;
__decorate([
(0, swagger_1.ApiPropertyOptional)({ example: 'user123', description: 'Filter by user ID' }),
(0, class_validator_1.IsOptional)(),
(0, class_validator_1.IsString)(),
__metadata("design:type", String)
], FileQueryDto.prototype, "userId", void 0);
__decorate([
(0, swagger_1.ApiPropertyOptional)({
example: 'image',
enum: ['image', 'document', 'video', 'audio'],
description: 'File type filter'
}),
(0, class_validator_1.IsOptional)(),
(0, class_validator_1.IsEnum)(['image', 'document', 'video', 'audio']),
__metadata("design:type", String)
], FileQueryDto.prototype, "fileType", void 0);
__decorate([
(0, swagger_1.ApiPropertyOptional)({ example: 'image/jpeg', description: 'MIME type filter' }),
(0, class_validator_1.IsOptional)(),
(0, class_validator_1.IsString)(),
__metadata("design:type", String)
], FileQueryDto.prototype, "mimeType", void 0);
__decorate([
(0, swagger_1.ApiPropertyOptional)({ example: 1000, description: 'Minimum file size in bytes' }),
(0, class_validator_1.IsOptional)(),
(0, class_validator_1.IsNumber)(),
(0, class_validator_1.Min)(0),
(0, class_transformer_1.Type)(() => Number),
__metadata("design:type", Number)
], FileQueryDto.prototype, "minSize", void 0);
__decorate([
(0, swagger_1.ApiPropertyOptional)({ example: 5000000, description: 'Maximum file size in bytes' }),
(0, class_validator_1.IsOptional)(),
(0, class_validator_1.IsNumber)(),
(0, class_validator_1.Min)(0),
(0, class_transformer_1.Type)(() => Number),
__metadata("design:type", Number)
], FileQueryDto.prototype, "maxSize", void 0);