Skip to content

Commit

Permalink
chore: intermediate progress
Browse files Browse the repository at this point in the history
  • Loading branch information
letehaha committed Jul 7, 2023
1 parent eb02806 commit 148fcc8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion shared-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ export enum CATEGORY_TYPES {

export * from './api';
export * from './models';
export * as endpointsPayloadTypes from './routes';
export * as endpointsTypes from './routes';
3 changes: 3 additions & 0 deletions shared-types/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export * from './monobank';

export type BodyPayload<T> = T
export type QueryPayload<T> = T
18 changes: 16 additions & 2 deletions shared-types/routes/monobank.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
export interface UpdateMonobankTransactionBody {
import { MonobankUserModel } from 'shared-types';
import { BodyPayload } from './index'

export interface UpdateMonobankTransactionBody extends BodyPayload<{
id: number;
categoryId?: number;
note?: string;
}
}> {}

export interface PairMonobankAccountBody extends BodyPayload<{
token: MonobankUserModel['apiToken']
}> {}

export interface UpdateMonobankUserBody extends BodyPayload<{
apiToken?: string;
name?: string;
webHookUrl?: string;
clientId?: string;
}> {}
10 changes: 6 additions & 4 deletions src/controllers/banks/monobank.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
PAYMENT_TYPES,
MonobankAccountModel,
MonobankUserModel,
endpointsPayloadTypes,
endpointsTypes,
} from 'shared-types';
import {
CustomResponse,
Expand Down Expand Up @@ -154,7 +154,7 @@ async function createMonoTransaction(
}

export const pairAccount = async (req, res: CustomResponse) => {
const { token } = req.body;
const { token }: endpointsTypes.PairMonobankAccountBody = req.body;
const { id } = req.user;

try {
Expand Down Expand Up @@ -279,13 +279,15 @@ export const getUser = async (req, res: CustomResponse) => {

export const updateUser = async (req, res: CustomResponse) => {
const { id: systemUserId } = req.user;
const { apiToken, name } = req.body;
const { apiToken, name, webHookUrl, clientId }: endpointsTypes.UpdateMonobankUserBody = req.body;

try {
const user = await monobankUsersService.updateUser({
systemUserId,
apiToken,
name,
webHookUrl,
clientId,
});

return res.status(200).json({
Expand Down Expand Up @@ -360,7 +362,7 @@ export const updateTransaction = async (req, res: CustomResponse) => {
id,
categoryId,
note,
}: endpointsPayloadTypes.UpdateMonobankTransactionBody = req.body;
}: endpointsTypes.UpdateMonobankTransactionBody = req.body;

try {
const transaction = await monobankTransactionsService.updateTransactionById({
Expand Down
11 changes: 4 additions & 7 deletions src/models/banks/monobank/Users.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ForeignKey,
Length,
} from 'sequelize-typescript';
import { endpointsTypes } from 'shared-types';
import { GenericSequelizeModelAttributes } from '@common/types';
import Users from '../../Users.model';

Expand Down Expand Up @@ -63,20 +64,16 @@ export const getUserBySystemId = async (
return user;
};

export interface MonoUserUpdatePayload {
export interface MonoUserUpdatePayload extends endpointsTypes.UpdateMonobankUserBody {
systemUserId: number;
clientId?: string;
apiToken?: string;
name?: string;
webHookUrl?: string;
}
export const updateUser = async (
{ systemUserId, clientId, ...payload }: MonoUserUpdatePayload,
attributes: GenericSequelizeModelAttributes = {},
) => {
const where: {
systemUserId: number
clientId?: string
systemUserId: MonoUserUpdatePayload['systemUserId'];
clientId?: MonoUserUpdatePayload['clientId'];
} = { systemUserId }

if (clientId) {
Expand Down

0 comments on commit 148fcc8

Please sign in to comment.