修改commit的两个trigger

This commit is contained in:
Xu Chang 2023-10-10 12:09:23 +08:00
parent 7cba48f8ad
commit f7ea97cfcf
12 changed files with 38 additions and 135 deletions

View File

@ -25,7 +25,7 @@ export declare abstract class BackendRuntimeContext<ED extends EntityDict & Base
* *
*/ */
protected initialized(): Promise<void>; protected initialized(): Promise<void>;
private initialize; protected initialize(data?: SerializedData): Promise<void>;
getApplicationId(): ED["application"]["Schema"]["id"] | undefined; getApplicationId(): ED["application"]["Schema"]["id"] | undefined;
getSystemId(): ED["application"]["Schema"]["systemId"] | undefined; getSystemId(): ED["application"]["Schema"]["systemId"] | undefined;
getApplication(): Partial<ED["application"]["Schema"]> | undefined; getApplication(): Partial<ED["application"]["Schema"]> | undefined;
@ -34,7 +34,7 @@ export declare abstract class BackendRuntimeContext<ED extends EntityDict & Base
getToken(allowUnloggedIn?: boolean): Partial<ED["token"]["Schema"]> | undefined; getToken(allowUnloggedIn?: boolean): Partial<ED["token"]["Schema"]> | undefined;
getCurrentUserId(allowUnloggedIn?: boolean): string; getCurrentUserId(allowUnloggedIn?: boolean): string;
setTemporaryUserId(userId: string | undefined): void; setTemporaryUserId(userId: string | undefined): void;
toString(): string; protected getSerializedData(): SerializedData;
isRoot(): boolean; isRoot(): boolean;
isReallyRoot(): boolean; isReallyRoot(): boolean;
sendMessage(data: ED['message']['CreateSingle']['data']): Promise<import("oak-domain").OperationResult<ED>>; sendMessage(data: ED['message']['CreateSingle']['data']): Promise<import("oak-domain").OperationResult<ED>>;

View File

@ -189,11 +189,14 @@ export class BackendRuntimeContext extends BRC {
setTemporaryUserId(userId) { setTemporaryUserId(userId) {
this.temporaryUserId = userId; this.temporaryUserId = userId;
} }
toString() { getSerializedData() {
if (this.rootMode) { const data = super.getSerializedData();
return JSON.stringify({ rootMode: true }); return {
} ...data,
return JSON.stringify({ a: this.application?.id, t: this.token?.id }); a: this.application?.id,
t: this.token?.id,
rm: this.rootMode,
};
} }
isRoot() { isRoot() {
if (this.rootMode) { if (this.rootMode) {

View File

@ -11,6 +11,7 @@ export type AspectDict<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
export interface SerializedData extends Fsd { export interface SerializedData extends Fsd {
a?: string; a?: string;
t?: string; t?: string;
rm?: boolean;
} }
export declare abstract class FrontendRuntimeContext<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>, AD extends AspectDict<ED, Cxt>> extends Frc<ED, Cxt, AD> implements RuntimeContext { export declare abstract class FrontendRuntimeContext<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>, AD extends AspectDict<ED, Cxt>> extends Frc<ED, Cxt, AD> implements RuntimeContext {
private application; private application;

View File

@ -33,36 +33,8 @@ const triggers = [
strict: 'makeSure', strict: 'makeSure',
entity: 'extraFile', entity: 'extraFile',
action: 'remove', action: 'remove',
fn: async ({ operation }, context) => { fn: async ({ rows }, context) => {
const { filter } = operation; for (const extraFile of rows) {
const extraFileList = await context.select('extraFile', {
data: {
id: 1,
origin: 1,
type: 1,
bucket: 1,
objectId: 1,
tag1: 1,
tag2: 1,
filename: 1,
md5: 1,
entity: 1,
entityId: 1,
extra1: 1,
extension: 1,
size: 1,
sort: 1,
fileType: 1,
isBridge: 1,
uploadState: 1,
uploadMeta: 1,
},
filter,
}, {
includedDeleted: true,
dontCollect: true,
});
for (const extraFile of extraFileList) {
const { origin } = extraFile; const { origin } = extraFile;
const uploader = getCos(origin); const uploader = getCos(origin);
await uploader.removeFile(extraFile, context); await uploader.removeFile(extraFile, context);

View File

@ -240,17 +240,11 @@ const triggers = [
action: 'create', action: 'create',
when: 'commit', when: 'commit',
strict: 'takeEasy', strict: 'takeEasy',
fn: async ({ operation }, context) => { fn: async ({ rows }, context) => {
const { data } = operation;
const closeRootMode = context.openRootMode(); const closeRootMode = context.openRootMode();
try { try {
if (data instanceof Array) { for (const row of rows) {
for (const d of data) { await sendNotification(row, context);
await sendNotification(d, context);
}
}
else {
await sendNotification(data, context);
} }
} }
catch (err) { catch (err) {

View File

@ -25,7 +25,7 @@ export declare abstract class BackendRuntimeContext<ED extends EntityDict & Base
* *
*/ */
protected initialized(): Promise<void>; protected initialized(): Promise<void>;
private initialize; protected initialize(data?: SerializedData): Promise<void>;
getApplicationId(): ED["application"]["Schema"]["id"] | undefined; getApplicationId(): ED["application"]["Schema"]["id"] | undefined;
getSystemId(): ED["application"]["Schema"]["systemId"] | undefined; getSystemId(): ED["application"]["Schema"]["systemId"] | undefined;
getApplication(): Partial<ED["application"]["Schema"]> | undefined; getApplication(): Partial<ED["application"]["Schema"]> | undefined;
@ -34,7 +34,7 @@ export declare abstract class BackendRuntimeContext<ED extends EntityDict & Base
getToken(allowUnloggedIn?: boolean): Partial<ED["token"]["Schema"]> | undefined; getToken(allowUnloggedIn?: boolean): Partial<ED["token"]["Schema"]> | undefined;
getCurrentUserId(allowUnloggedIn?: boolean): string; getCurrentUserId(allowUnloggedIn?: boolean): string;
setTemporaryUserId(userId: string | undefined): void; setTemporaryUserId(userId: string | undefined): void;
toString(): string; protected getSerializedData(): SerializedData;
isRoot(): boolean; isRoot(): boolean;
isReallyRoot(): boolean; isReallyRoot(): boolean;
sendMessage(data: ED['message']['CreateSingle']['data']): Promise<import("oak-domain").OperationResult<ED>>; sendMessage(data: ED['message']['CreateSingle']['data']): Promise<import("oak-domain").OperationResult<ED>>;

View File

@ -192,11 +192,14 @@ class BackendRuntimeContext extends oak_frontend_base_1.BackendRuntimeContext {
setTemporaryUserId(userId) { setTemporaryUserId(userId) {
this.temporaryUserId = userId; this.temporaryUserId = userId;
} }
toString() { getSerializedData() {
if (this.rootMode) { const data = super.getSerializedData();
return JSON.stringify({ rootMode: true }); return {
} ...data,
return JSON.stringify({ a: this.application?.id, t: this.token?.id }); a: this.application?.id,
t: this.token?.id,
rm: this.rootMode,
};
} }
isRoot() { isRoot() {
if (this.rootMode) { if (this.rootMode) {

View File

@ -11,6 +11,7 @@ export type AspectDict<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
export interface SerializedData extends Fsd { export interface SerializedData extends Fsd {
a?: string; a?: string;
t?: string; t?: string;
rm?: boolean;
} }
export declare abstract class FrontendRuntimeContext<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>, AD extends AspectDict<ED, Cxt>> extends Frc<ED, Cxt, AD> implements RuntimeContext { export declare abstract class FrontendRuntimeContext<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>, AD extends AspectDict<ED, Cxt>> extends Frc<ED, Cxt, AD> implements RuntimeContext {
private application; private application;

View File

@ -35,36 +35,8 @@ const triggers = [
strict: 'makeSure', strict: 'makeSure',
entity: 'extraFile', entity: 'extraFile',
action: 'remove', action: 'remove',
fn: async ({ operation }, context) => { fn: async ({ rows }, context) => {
const { filter } = operation; for (const extraFile of rows) {
const extraFileList = await context.select('extraFile', {
data: {
id: 1,
origin: 1,
type: 1,
bucket: 1,
objectId: 1,
tag1: 1,
tag2: 1,
filename: 1,
md5: 1,
entity: 1,
entityId: 1,
extra1: 1,
extension: 1,
size: 1,
sort: 1,
fileType: 1,
isBridge: 1,
uploadState: 1,
uploadMeta: 1,
},
filter,
}, {
includedDeleted: true,
dontCollect: true,
});
for (const extraFile of extraFileList) {
const { origin } = extraFile; const { origin } = extraFile;
const uploader = (0, cos_1.getCos)(origin); const uploader = (0, cos_1.getCos)(origin);
await uploader.removeFile(extraFile, context); await uploader.removeFile(extraFile, context);

View File

@ -242,17 +242,11 @@ const triggers = [
action: 'create', action: 'create',
when: 'commit', when: 'commit',
strict: 'takeEasy', strict: 'takeEasy',
fn: async ({ operation }, context) => { fn: async ({ rows }, context) => {
const { data } = operation;
const closeRootMode = context.openRootMode(); const closeRootMode = context.openRootMode();
try { try {
if (data instanceof Array) { for (const row of rows) {
for (const d of data) { await sendNotification(row, context);
await sendNotification(d, context);
}
}
else {
await sendNotification(data, context);
} }
} }
catch (err) { catch (err) {

View File

@ -41,40 +41,8 @@ const triggers: Trigger<EntityDict, 'extraFile', BackendRuntimeContext<EntityDic
strict: 'makeSure', strict: 'makeSure',
entity: 'extraFile', entity: 'extraFile',
action: 'remove', action: 'remove',
fn: async ({ operation }, context) => { fn: async ({ rows }, context) => {
const { filter } = operation; for (const extraFile of rows) {
const extraFileList = await context.select(
'extraFile',
{
data: {
id: 1,
origin: 1,
type: 1,
bucket: 1,
objectId: 1,
tag1: 1,
tag2: 1,
filename: 1,
md5: 1,
entity: 1,
entityId: 1,
extra1: 1,
extension: 1,
size: 1,
sort: 1,
fileType: 1,
isBridge: 1,
uploadState: 1,
uploadMeta: 1,
},
filter,
},
{
includedDeleted: true,
dontCollect: true,
}
);
for (const extraFile of extraFileList) {
const { origin } = extraFile; const { origin } = extraFile;
const uploader = getCos(origin!); const uploader = getCos(origin!);
await uploader.removeFile(extraFile as EntityDict['extraFile']['OpSchema'], context); await uploader.removeFile(extraFile as EntityDict['extraFile']['OpSchema'], context);

View File

@ -12,7 +12,7 @@ import { sendSms } from '../utils/sms';
import { tryMakeSmsNotification } from './message'; import { tryMakeSmsNotification } from './message';
import { composeDomainUrl } from '../utils/domain'; import { composeDomainUrl } from '../utils/domain';
async function sendNotification(notification: CreateNotificationData, context: BackendRuntimeContext<EntityDict>) { async function sendNotification(notification: EntityDict['notification']['OpSchema'], context: BackendRuntimeContext<EntityDict>) {
const { data, templateId, channel, messageSystemId, data1, id } = notification; const { data, templateId, channel, messageSystemId, data1, id } = notification;
const [messageSystem] = await context.select('messageSystem', { const [messageSystem] = await context.select('messageSystem', {
data: { data: {
@ -281,16 +281,11 @@ const triggers: Trigger<EntityDict, 'notification', BackendRuntimeContext<Entity
action: 'create', action: 'create',
when: 'commit', when: 'commit',
strict: 'takeEasy', strict: 'takeEasy',
fn: async ({ operation }, context) => { fn: async ({ rows }, context) => {
const { data } = operation;
const closeRootMode = context.openRootMode(); const closeRootMode = context.openRootMode();
try { try {
if (data instanceof Array) { for (const row of rows) {
for (const d of data) { await sendNotification(row, context);
await sendNotification(d, context);
}
} else {
await sendNotification(data, context);
} }
} catch (err) { } catch (err) {
closeRootMode(); closeRootMode();