mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
update interface.ts
This commit is contained in:
1 parent
10956f1fee
commit
d4e849a133
8 files changed
+99
-71
No files matched your search
+12
-14
@@ -1,10 +1,10 @@
|
||||
import { ObjectID, QuerySelector } from 'mongodb';
|
||||
import { MessageNotFoundError } from '../error';
|
||||
import { ObjectID } from 'mongodb';
|
||||
import { Mdoc } from '../interface';
|
||||
import * as db from '../service/db';
|
||||
|
||||
const coll = db.collection('message');
|
||||
|
||||
export async function send(from: number, to: number, content: string) {
|
||||
export async function send(from: number, to: number, content: string): Promise<Mdoc> {
|
||||
const res = await coll.insertOne({
|
||||
from, to, content, unread: true,
|
||||
});
|
||||
@@ -13,27 +13,25 @@ export async function send(from: number, to: number, content: string) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function get(_id: ObjectID) {
|
||||
const doc = await coll.findOne({ _id });
|
||||
if (!doc) throw new MessageNotFoundError(_id);
|
||||
return doc;
|
||||
export async function get(_id: ObjectID): Promise<Mdoc> {
|
||||
return await coll.findOne({ _id });
|
||||
}
|
||||
|
||||
export function getByUser(uid: number) {
|
||||
return coll.find({ $or: [{ from: uid }, { to: uid }] }).sort('_id', 1).toArray();
|
||||
export async function getByUser(uid: number): Promise<Mdoc[]> {
|
||||
return await coll.find({ $or: [{ from: uid }, { to: uid }] }).sort('_id', 1).toArray();
|
||||
}
|
||||
|
||||
export function getMany<T>(query: QuerySelector<T>, sort, page: number, limit: number) {
|
||||
return coll.find(query).sort(sort)
|
||||
export async function getMany(query: any, sort: any, page: number, limit: number): Promise<Mdoc[]> {
|
||||
return await coll.find(query).sort(sort)
|
||||
.skip((page - 1) * limit).limit(limit)
|
||||
.toArray();
|
||||
}
|
||||
|
||||
export function del(_id: ObjectID) {
|
||||
return coll.deleteOne({ _id });
|
||||
export async function del(_id: ObjectID) {
|
||||
return await coll.deleteOne({ _id });
|
||||
}
|
||||
|
||||
export function count<T>(query: QuerySelector<T>) {
|
||||
export function count(query: any) {
|
||||
return coll.find(query).count();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user