update interface.ts

This commit is contained in:
undefined committed 2020-07-14 17:17:49 +08:00
1 parent 10956f1fee
commit d4e849a133
8 files changed
+99 -71

No files matched your search

+9 -3
View File
@@ -1,13 +1,19 @@
import * as db from '../service/db';
import { Bdoc } from '../interface';
const coll = db.collection('blacklist');
export async function add(ip: string) {
export async function add(ip: string): Promise<Bdoc> {
const expireAt = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
return coll.findOneAndUpdate({ _id: ip }, { $set: { expireAt } }, { upsert: true });
const res = await coll.findOneAndUpdate(
{ _id: ip },
{ $set: { expireAt } },
{ upsert: true, returnOriginal: false },
);
return res.value;
}
export function get(ip: string) {
export function get(ip: string): Promise<Bdoc> {
return coll.findOne({ _id: ip });
}