-
Notifications
You must be signed in to change notification settings - Fork 0
/
transferWithdrawalScheduled.ts
70 lines (67 loc) · 1.53 KB
/
transferWithdrawalScheduled.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import * as z from 'zod'
import { extract } from './extract'
import { Parser } from './parser'
/**
* 振込予約のご確認
*/
const transferWithdrawalScheduledSchema = z.object({
type: z.literal('transferWithdrawalScheduled'),
/**
* 振込指定日
*/
scheduledDate: z.string(),
/**
* 受付番号
*/
number: z.string(),
/**
* 受取人名
*/
recipient: z.string(),
/**
* 振込金額
*/
amount: z.number(),
})
export type TransferWithdrawalScheduled = z.infer<
typeof transferWithdrawalScheduledSchema
>
export const transferWithdrawalScheduledParser: Parser<TransferWithdrawalScheduled> = ({
subject,
text,
}) => {
if (subject !== '振込予約のご確認') {
return
}
const scheduledDate = extract(
text,
/振込指定日:(?<year>\d{4})\/(?<month>\d{2})\/(?<day>\d{2})/,
)
.map(_ => `${_.year}-${_.month}-${_.day}`)
.pop()
const number = extract(text, /受付番号:(?<number>\d+)/)
.map(_ => _.number)
.pop()
const recipient = extract(text, /受取人名:(?<name>.+)/)
.map(_ => _.name)
.pop()
const amount = extract(text, /振込金額:(?<amount>[\d,]+)円/)
.map(_ => parseInt(_.amount.replace(/,/g, '')))
.filter(_ => !Number.isNaN(_))
.pop()
if (
typeof scheduledDate === 'string' &&
typeof number === 'string' &&
typeof recipient === 'string' &&
typeof amount === 'number'
) {
return {
type: 'transferWithdrawalScheduled',
scheduledDate,
number,
recipient,
amount,
}
}
return
}