115 lines
4.9 KiB
JavaScript
115 lines
4.9 KiB
JavaScript
"use strict";
|
|
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);
|
|
};
|
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.TransactionsController = void 0;
|
|
const common_1 = require("@nestjs/common");
|
|
const transactions_service_1 = require("./transactions.service");
|
|
const transaction_dto_1 = require("./transaction.dto");
|
|
let TransactionsController = class TransactionsController {
|
|
tx;
|
|
constructor(tx) {
|
|
this.tx = tx;
|
|
}
|
|
list(walletId) {
|
|
return this.tx.list(walletId);
|
|
}
|
|
create(walletId, body) {
|
|
return this.tx.create(walletId, body);
|
|
}
|
|
async exportCsv(walletId, from, to, category, direction, res) {
|
|
const rows = await this.tx.listWithFilters(walletId, { from, to, category, direction });
|
|
res.setHeader('Content-Type', 'text/csv; charset=utf-8');
|
|
res.setHeader('Content-Disposition', `attachment; filename="transactions_${walletId}.csv"`);
|
|
res.write(`date,category,memo,direction,amount\n`);
|
|
const esc = (v) => {
|
|
if (v === null || v === undefined)
|
|
return '';
|
|
const s = String(v);
|
|
return /[",\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
|
|
};
|
|
for (const r of rows) {
|
|
const line = [
|
|
r.date.toISOString(),
|
|
esc(r.category ?? ''),
|
|
esc(r.memo ?? ''),
|
|
r.direction,
|
|
r.amount.toString(),
|
|
].join(',');
|
|
res.write(line + '\n');
|
|
}
|
|
res.end();
|
|
}
|
|
async update(walletId, id, body) {
|
|
try {
|
|
const parsed = transaction_dto_1.TransactionUpdateSchema.parse(body);
|
|
return this.tx.update(walletId, id, parsed);
|
|
}
|
|
catch (e) {
|
|
throw new common_1.BadRequestException(e?.errors ?? 'Invalid payload');
|
|
}
|
|
}
|
|
delete(walletId, id) {
|
|
return this.tx.delete(walletId, id);
|
|
}
|
|
};
|
|
exports.TransactionsController = TransactionsController;
|
|
__decorate([
|
|
(0, common_1.Get)(),
|
|
__param(0, (0, common_1.Param)('walletId')),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [String]),
|
|
__metadata("design:returntype", void 0)
|
|
], TransactionsController.prototype, "list", null);
|
|
__decorate([
|
|
(0, common_1.Post)(),
|
|
__param(0, (0, common_1.Param)('walletId')),
|
|
__param(1, (0, common_1.Body)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [String, Object]),
|
|
__metadata("design:returntype", void 0)
|
|
], TransactionsController.prototype, "create", null);
|
|
__decorate([
|
|
(0, common_1.Get)('export.csv'),
|
|
__param(0, (0, common_1.Param)('walletId')),
|
|
__param(1, (0, common_1.Query)('from')),
|
|
__param(2, (0, common_1.Query)('to')),
|
|
__param(3, (0, common_1.Query)('category')),
|
|
__param(4, (0, common_1.Query)('direction')),
|
|
__param(5, (0, common_1.Res)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [String, Object, Object, Object, Object, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], TransactionsController.prototype, "exportCsv", null);
|
|
__decorate([
|
|
(0, common_1.Put)(':id'),
|
|
__param(0, (0, common_1.Param)('walletId')),
|
|
__param(1, (0, common_1.Param)('id')),
|
|
__param(2, (0, common_1.Body)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [String, String, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], TransactionsController.prototype, "update", null);
|
|
__decorate([
|
|
(0, common_1.Delete)(':id'),
|
|
__param(0, (0, common_1.Param)('walletId')),
|
|
__param(1, (0, common_1.Param)('id')),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [String, String]),
|
|
__metadata("design:returntype", void 0)
|
|
], TransactionsController.prototype, "delete", null);
|
|
exports.TransactionsController = TransactionsController = __decorate([
|
|
(0, common_1.Controller)('wallets/:walletId/transactions'),
|
|
__metadata("design:paramtypes", [transactions_service_1.TransactionsService])
|
|
], TransactionsController);
|
|
//# sourceMappingURL=transactions.controller.js.map
|