add types. TODO make logic match desired types.

This commit is contained in:
Kiara Grouwstra 2021-10-04 12:58:37 +02:00
parent b538990030
commit 5be4632a29
3 changed files with 13 additions and 11 deletions

View File

@ -1,21 +1,22 @@
"use strict";
import { mergeMap } from "rxjs/operators";
import { of, from, concat } from "rxjs";
import { of, from, concat, Observable } from "rxjs";
import { List, MollieClient, MollieOptions, Payment } from "@mollie/api-client";
export const mollieKeys = {
leden: process.env.MOLLIE_API_KEY_LEDEN,
doemee: process.env.MOLLIE_API_KEY_DOEMEE,
shop: process.env.MOLLIE_API_KEY_SHOP,
doneer: process.env.MOLLIE_API_KEY_DONEER,
leden: process.env.MOLLIE_API_KEY_LEDEN || '',
doemee: process.env.MOLLIE_API_KEY_DOEMEE || '',
shop: process.env.MOLLIE_API_KEY_SHOP || '',
doneer: process.env.MOLLIE_API_KEY_DONEER || '',
};
export function unrollResult(result) {
export function unrollResult(result: List<Payment>): Observable<Payment> {
// log(result);
// const { count, nextPage, links } = result;
return concat(of(result), of(result.nextPage ? listAll(result.nextPage()) : []));
}
export function listAll(page$) {
export function listAll(page$: Promise<List<Payment>>): Observable<Payment> {
return from(page$).pipe(
mergeMap(unrollResult)
);

View File

@ -1,3 +1,4 @@
import Airtable from 'airtable';
import { tbl } from '../src/airtable';
test('airtable can print records', () => {
@ -7,7 +8,7 @@ test('airtable can print records', () => {
// .eachPage()
// .forEach()
.then(records => {
records.forEach(record => {
records.forEach((record: Airtable.Record<any>) => {
console.log(record.fields);
});
});

View File

@ -2,7 +2,7 @@ import { createMollieClient } from '@mollie/api-client';
import { mollieKeys, listAll } from '../src/mollie';
const log = console.log.bind(console);
test('airtable can print records', (done) => {
test('airtable can print records', (done: () => void) => {
const mollieClient = createMollieClient({ apiKey: mollieKeys.leden });
// const entity = mollieClient.customers;
const entity = mollieClient.payments;
@ -13,10 +13,10 @@ test('airtable can print records', (done) => {
log('just before subscribe');
obs.subscribe({
next(x) {
next(x: any) {
log('got value ' + x);
},
error(err) {
error(err: string) {
console.error('something wrong occurred: ' + err);
},
complete() {