Skip to content

Commit

Permalink
added dateformat and a minor fix with relationship being null
Browse files Browse the repository at this point in the history
  • Loading branch information
Jsnxyz committed Apr 23, 2024
1 parent ef9a3d1 commit a44f98c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/utils/api-to-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function apiResponseToInvoiceOutput(
return {
...attributes,
id: invoice.id,
membershipId: invoice.relationships.membership.data.id,
membershipId: invoice.relationships.membership?.data?.id,
};
}

Expand Down
14 changes: 8 additions & 6 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const listRecentInvoices = async (
const space = await spaceForSubdomain(z, subdomain);
if (!space) return [];
const spaceId = space.id;
const [from, to] = getDateRange();
const [from, to] = getDateRange("yyyy-MM-dd");
const response = await z.request({
url: `https://api.cobot.me/spaces/${spaceId}/invoices`,
method: "GET",
Expand Down Expand Up @@ -297,10 +297,12 @@ export const createActivity = async (
return object;
};

const getDateRange = (): [string, string] => {
const getDateRange = (format?: string): [string, string] => {
const now = DateTime.now();
const lastMonth = now.minus({ months: 1 }).toISO();
const nextMonth = now.plus({ months: 1 }).toISO();

return [lastMonth, nextMonth];
const lastMonth = now.minus({ months: 1 });
const nextMonth = now.plus({ months: 1 });
if (!format) {
return [lastMonth.toISO(), nextMonth.toISO()];
}
return [lastMonth.toFormat(format), nextMonth.toFormat(format)];
};

0 comments on commit a44f98c

Please sign in to comment.