适配新的domain
This commit is contained in:
parent
4b5259ec0b
commit
a169340686
|
|
@ -1,5 +1,6 @@
|
|||
import { OperateOption, EntityDict, Context, SelectOption, SelectRowShape } from 'oak-domain/lib/types';
|
||||
export declare function operate<ED extends EntityDict, T extends keyof ED, Cxt extends Context<ED>, OP extends OperateOption>(params: {
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
export declare function operate<ED extends BaseEntityDict & EntityDict, T extends keyof ED, Cxt extends Context<ED>, OP extends OperateOption>(params: {
|
||||
entity: T;
|
||||
operation: ED[T]['Operation'] | ED[T]['Operation'][];
|
||||
option?: OP;
|
||||
|
|
|
|||
15
lib/crud.js
15
lib/crud.js
|
|
@ -4,7 +4,20 @@ exports.select = exports.operate = void 0;
|
|||
async function operate(params, context) {
|
||||
const { entity, operation, option } = params;
|
||||
if (operation instanceof Array) {
|
||||
return await Promise.all(operation.map((oper) => context.rowStore.operate(entity, oper, context, option)));
|
||||
const result = [];
|
||||
for (const oper of operation) {
|
||||
const r = await context.rowStore.operate(entity, oper, context, option);
|
||||
result.push(r);
|
||||
if (entity !== 'Oper') {
|
||||
/* await context.rowStore.operate('oper', {
|
||||
action: 'create',
|
||||
data: {
|
||||
|
||||
}
|
||||
}, context); */
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return await context.rowStore.operate(entity, operation, context, option);
|
||||
}
|
||||
|
|
|
|||
20
src/crud.ts
20
src/crud.ts
|
|
@ -1,12 +1,24 @@
|
|||
import { OperateOption, EntityDict, Context, SelectOption, SelectRowShape } from 'oak-domain/lib/types';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
|
||||
export async function operate<ED extends EntityDict, T extends keyof ED, Cxt extends Context<ED>, OP extends OperateOption>(
|
||||
export async function operate<ED extends BaseEntityDict & EntityDict, T extends keyof ED, Cxt extends Context<ED>, OP extends OperateOption>(
|
||||
params: { entity: T, operation: ED[T]['Operation'] | ED[T]['Operation'][], option?: OP }, context: Cxt) {
|
||||
const { entity, operation, option } = params;
|
||||
if (operation instanceof Array) {
|
||||
return await Promise.all(operation.map(
|
||||
(oper) => context.rowStore.operate(entity, oper, context, option)
|
||||
));
|
||||
const result = [];
|
||||
for (const oper of operation) {
|
||||
const r = await context.rowStore.operate(entity, oper, context, option);
|
||||
result.push(r);
|
||||
if (entity !== 'Oper') {
|
||||
/* await context.rowStore.operate('oper', {
|
||||
action: 'create',
|
||||
data: {
|
||||
|
||||
}
|
||||
}, context); */
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return await context.rowStore.operate(entity, operation, context, option);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue