Skip to content

Commit

Permalink
fix: settings update
Browse files Browse the repository at this point in the history
  • Loading branch information
jroehl committed Apr 18, 2022
1 parent b287dd7 commit 3268325
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 29 deletions.
136 changes: 119 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
"dependencies": {
"@contentful/rich-text-plain-text-renderer": "^15.11.1",
"@middy/core": "^2.5.7",
"@middy/http-error-handler": "^2.5.7",
"@middy/http-json-body-parser": "^2.5.7",
"@middy/validator": "^2.5.7",
"aws-sdk": "^2.824.0",
"chrome-aws-lambda": "^10.0.0",
"contentful": "^9.0.3",
Expand Down
8 changes: 4 additions & 4 deletions src/functions/debitoor/handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
httpResponse,
ValidatedEventAPIGatewayProxyEvent,
ValidatedEventAPIGatewayProxyEvent
} from '@libs/apiGateway';
import { BOOK, LABEL_BILLED, MAIL } from '@libs/constants';
import { fetchCompanies } from '@libs/contentful';
Expand All @@ -9,7 +9,7 @@ import {
bookSendDraftInvoice,
changeCompany,
createDraftInvoices,
CreateDraftInvoicesResponse,
CreateDraftInvoicesResponse
} from '@libs/debitoor';
import { middyfy } from '@libs/lambda';
import {
Expand All @@ -18,7 +18,7 @@ import {
fetchTimeEntriesBetween,
filterClientTimeEntriesByCustomer,
filterTimeEntriesByLabel,
sanitizeTimeEntries,
sanitizeTimeEntries
} from '@libs/toggl';
import { clearCaches, getConfig, initTranslate, Logger } from '@libs/utils';
import 'source-map-support/register';
Expand Down Expand Up @@ -146,4 +146,4 @@ const handler: ValidatedEventAPIGatewayProxyEvent<typeof schema> = async (
}
};

export const main = middyfy(handler);
export const main = middyfy(handler, schema);
6 changes: 3 additions & 3 deletions src/functions/sheet/handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
httpResponse,
ValidatedEventAPIGatewayProxyEvent,
ValidatedEventAPIGatewayProxyEvent
} from '@libs/apiGateway';
import { createCsv } from '@libs/csv';
import { middyfy } from '@libs/lambda';
Expand All @@ -10,7 +10,7 @@ import {
fetchTimeEntriesBetween,
filterClientTimeEntriesByCustomer,
filterTimeEntriesByLabel,
sanitizeTimeEntries,
sanitizeTimeEntries
} from '@libs/toggl';
import { clearCaches, getConfig, Logger } from '@libs/utils';
import 'source-map-support/register';
Expand Down Expand Up @@ -72,4 +72,4 @@ const handler: ValidatedEventAPIGatewayProxyEvent<typeof schema> = async (
}
};

export const main = middyfy(handler);
export const main = middyfy(handler, schema);
6 changes: 3 additions & 3 deletions src/functions/sync-contentful/handler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
httpResponse,
ValidatedEventAPIGatewayProxyEvent,
ValidatedEventAPIGatewayProxyEvent
} from '@libs/apiGateway';
import {
updateDebitoorCustomers,
updateDebitoorProducts,
updateDebitoorProducts
} from '@libs/debitoor';
import { middyfy } from '@libs/lambda';
import { updateTogglClients, updateTogglProjects } from '@libs/toggl';
Expand All @@ -27,4 +27,4 @@ const handler: ValidatedEventAPIGatewayProxyEvent<unknown> = async () => {
}
};

export const main = middyfy(handler);
export const main = middyfy(handler, {});
1 change: 1 addition & 0 deletions src/libs/debitoor-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export interface LogoResponse {
// GENERATED WITH https://jvilk.com/MakeTypes/
export interface Settings {
customerSettings: CustomerSettings;
accountMigratedAt?: unknown;
supplierSettings: SupplierSettings;
invoiceSettings: InvoiceSettings;
quoteSettings: QuoteSettings;
Expand Down
4 changes: 4 additions & 0 deletions src/libs/debitoor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,14 @@ export const changeCompanyDetails = async (
settings.companyProfile.webSite = website;
settings.companyProfile.email = email;
settings.companyProfile.logoUrl = logoUrl;
settings.customerSettings.lastCustomerNumber =
settings.customerSettings.lastCustomerNumber ?? 1000;

settings.ccInfo.billingInfo.company = name;

delete settings.vatReported;
delete settings.accountMigratedAt;
delete settings.featuresQuota;

return fetch(`${BASE_URL}/${SETTINGS_PATH}`, {
method: 'PUT',
Expand Down
19 changes: 17 additions & 2 deletions src/libs/lambda.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import middy from '@middy/core';
import middyJsonBodyParser from '@middy/http-json-body-parser';
import httpErrorHandler from '@middy/http-error-handler';
import jsonBodyParser from '@middy/http-json-body-parser';

export const middyfy = (handler) => middy(handler).use(middyJsonBodyParser());
export const middyfy = (handler, inputSchema) =>
middy(handler)
.use(jsonBodyParser())
// .use(validator({ inputSchema }))
.use(
httpErrorHandler({
logger(error) {
try {
console.dir(error, { depth: null, colors: true });
} catch (error) {
console.log(error);
}
},
})
);

0 comments on commit 3268325

Please sign in to comment.