mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: add hooks for DomainDoc
This commit is contained in:
1 parent
b3aa0a5e09
commit
508e42b0eb
3 files changed
+21
-4
No files matched your search
@@ -43,6 +43,7 @@ langs:
|
|||||||
type: compiler
|
type: compiler
|
||||||
compile: /usr/bin/javac -d ${dir} -encoding utf8 ./Main.java
|
compile: /usr/bin/javac -d ${dir} -encoding utf8 ./Main.java
|
||||||
code_file: Main.java
|
code_file: Main.java
|
||||||
|
target: Main.class
|
||||||
execute: /usr/bin/java Main
|
execute: /usr/bin/java Main
|
||||||
py:
|
py:
|
||||||
type: compiler
|
type: compiler
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Dictionary } from 'lodash';
|
|||||||
import { FilterQuery } from 'mongodb';
|
import { FilterQuery } from 'mongodb';
|
||||||
import { BUILTIN_ROLES, PRIV } from './builtin';
|
import { BUILTIN_ROLES, PRIV } from './builtin';
|
||||||
import { DomainDoc } from '../interface';
|
import { DomainDoc } from '../interface';
|
||||||
|
import * as bus from '../service/bus';
|
||||||
import * as db from '../service/db';
|
import * as db from '../service/db';
|
||||||
|
|
||||||
const coll = db.collection('domain');
|
const coll = db.collection('domain');
|
||||||
@@ -39,20 +40,28 @@ export async function add(domainId: string, owner: number, name: string, bulleti
|
|||||||
gravatar: '',
|
gravatar: '',
|
||||||
pidCounter: 0,
|
pidCounter: 0,
|
||||||
};
|
};
|
||||||
|
await bus.serial('domain/create', ddoc);
|
||||||
await coll.insertOne(ddoc);
|
await coll.insertOne(ddoc);
|
||||||
return domainId;
|
return domainId;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get(domainId: string): Promise<DomainDoc | null> {
|
export async function get(domainId: string): Promise<DomainDoc | null> {
|
||||||
return coll.findOne({ _id: domainId });
|
const query: FilterQuery<DomainDoc> = { _id: domainId };
|
||||||
|
await bus.serial('domain/before-get', query);
|
||||||
|
const result = await coll.findOne(query);
|
||||||
|
await bus.serial('domain/get', result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMulti(query: FilterQuery<DomainDoc> = {}) {
|
export function getMulti(query: FilterQuery<DomainDoc> = {}) {
|
||||||
return coll.find(query);
|
return coll.find(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function edit(domainId: string, $set: Partial<DomainDoc>) {
|
export async function edit(domainId: string, $set: Partial<DomainDoc>) {
|
||||||
return coll.updateOne({ _id: domainId }, { $set });
|
await bus.serial('domain/before-update', domainId, $set);
|
||||||
|
const result = await coll.findOneAndUpdate({ _id: domainId }, { $set }, { returnOriginal: false });
|
||||||
|
await bus.serial('domain/update', domainId, $set, result.value);
|
||||||
|
return result.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function inc(domainId: string, field: keyof DomainDoc, n: number): Promise<number | null> {
|
export async function inc(domainId: string, field: keyof DomainDoc, n: number): Promise<number | null> {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { Logger } from '../logger';
|
|||||||
import {
|
import {
|
||||||
Mdoc, Pdoc, Rdoc, TrainingDoc, User,
|
Mdoc, Pdoc, Rdoc, TrainingDoc, User,
|
||||||
} from '../interface';
|
} from '../interface';
|
||||||
|
import { DomainDoc } from '../loader';
|
||||||
|
|
||||||
type DocType = import('../model/document').DocType;
|
type DocType = import('../model/document').DocType;
|
||||||
|
|
||||||
@@ -39,6 +40,12 @@ export interface EventMap {
|
|||||||
'user/message': (uid: number, mdoc: Mdoc, udoc: User) => void
|
'user/message': (uid: number, mdoc: Mdoc, udoc: User) => void
|
||||||
'user/get': (udoc: User) => void
|
'user/get': (udoc: User) => void
|
||||||
|
|
||||||
|
'domain/create': (ddoc: DomainDoc) => void
|
||||||
|
'domain/before-get': (query: FilterQuery<DomainDoc>) => void
|
||||||
|
'domain/get': (ddoc: DomainDoc) => void
|
||||||
|
'domain/before-update': (domainId: string, $set: Partial<DomainDoc>) => void
|
||||||
|
'domain/update': (domainId: string, $set: Partial<DomainDoc>, ddoc: DomainDoc) => void
|
||||||
|
|
||||||
'document/add': (doc: any) => VoidReturn
|
'document/add': (doc: any) => VoidReturn
|
||||||
'document/set': <T extends keyof DocType>
|
'document/set': <T extends keyof DocType>
|
||||||
(domainId: string, docType: T, docId: DocType[T], $set: any) => VoidReturn
|
(domainId: string, docType: T, docId: DocType[T], $set: any) => VoidReturn
|
||||||
|
|||||||
Reference in new issue
Block a user