Skip to content

Commit d75da1c

Browse files
committed
feat: add logout route
1 parent 53015a4 commit d75da1c

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/vault/domain/vault.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface SerializedTransaction {
1919
isCommitted: boolean;
2020
description?: string;
2121
createdAt: string; // Date como string JSON
22+
date: string; // Date como string JSON
2223
categoryId: string | null;
2324
type: 'expense' | 'income';
2425
vaultId: string;
@@ -121,7 +122,7 @@ export class Vault {
121122
transaction.categoryId = options.categoryId;
122123
}
123124
if (options.date !== undefined) {
124-
transaction.createdAt = options.date;
125+
transaction.date = options.date;
125126
}
126127

127128
if (options.type !== undefined) {
@@ -191,11 +192,9 @@ export class Vault {
191192
transaction.categoryId === categoryId &&
192193
transaction.type === 'expense' &&
193194
(month
194-
? new Date(transaction.createdAt).getMonth() + 1 === month
195+
? new Date(transaction.date).getMonth() + 1 === month
195196
: true) &&
196-
(year
197-
? new Date(transaction.createdAt).getFullYear() === year
198-
: true),
197+
(year ? new Date(transaction.date).getFullYear() === year : true),
199198
)
200199
.reduce(
201200
(total, transaction) => total + Math.abs(transaction.amount),
@@ -235,7 +234,7 @@ export class Vault {
235234
date = { month: now.getMonth() + 1, year: now.getFullYear() };
236235
}
237236

238-
const transactionDate = new Date(transaction.createdAt);
237+
const transactionDate = new Date(transaction.date);
239238
const transactionMonth = transactionDate.getMonth() + 1;
240239
const transactionYear = transactionDate.getFullYear();
241240

@@ -255,7 +254,7 @@ export class Vault {
255254
const now = new Date();
256255
date = { month: now.getMonth() + 1, year: now.getFullYear() };
257256
}
258-
const transactionDate = new Date(transaction.createdAt);
257+
const transactionDate = new Date(transaction.date);
259258
const transactionMonth = transactionDate.getMonth() + 1;
260259
const transactionYear = transactionDate.getFullYear();
261260
if (transactionMonth === date.month && transactionYear === date.year) {
@@ -296,6 +295,7 @@ export class Vault {
296295
isCommitted: transaction.isCommitted,
297296
description: transaction.description,
298297
createdAt: transaction.createdAt.toISOString(),
298+
date: transaction.date.toISOString(),
299299
categoryId: transaction.categoryId,
300300
type: transaction.type,
301301
vaultId: transaction.vaultId,

src/vault/vault.controller.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ export class VaultController {
216216
return categories;
217217
}
218218

219+
@Post('logout')
220+
logout(@Res({ passthrough: true }) response: Response) {
221+
response.clearCookie('vault_access_token');
222+
return {
223+
message: 'Logout realizado com sucesso',
224+
};
225+
}
226+
219227
@Post('authenticate')
220228
async authenticate(
221229
@Body() data: { accessToken: string },

0 commit comments

Comments
 (0)