translateCascadeRelationFilterMaker中的小笔误
This commit is contained in:
parent
ef8a6428af
commit
912e68047a
|
|
@ -359,7 +359,7 @@ function translateCascadeRelationFilterMaker(schema, lch, entity2, pathPrefix) {
|
|||
var getForeignKeyId_1 = function (d) {
|
||||
if (relation === 2) {
|
||||
if (d.entity === attr && typeof d.entityId === 'string') {
|
||||
return d.entitId;
|
||||
return d.entityId;
|
||||
}
|
||||
throw new Exception_1.OakUserUnpermittedException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -841,7 +841,7 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
data: opData,
|
||||
beforeFns,
|
||||
afterFns,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// 对插入的数据,没有初始值的属性置null
|
||||
|
|
@ -870,7 +870,7 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
else {
|
||||
processSingle(data as ED[T]['CreateSingle']['data']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 对更新的数据,去掉所有的undefined属性
|
||||
protected preProcessDataUpdated(data: Record<string, any>) {
|
||||
|
|
@ -880,12 +880,12 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
undefinedKeys.forEach(
|
||||
ele => unset(data, ele)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
judgeRelation(entity: keyof ED, attr: string) {
|
||||
judgeRelation(entity: keyof ED, attr: string) {
|
||||
return judgeRelation(this.storageSchema, entity, attr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 和具体的update过程无关的例程放在这里,包括对later动作的处理、对oper的记录以及对record的收集等
|
||||
|
|
@ -898,7 +898,7 @@ judgeRelation(entity: keyof ED, attr: string) {
|
|||
operation: ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'],
|
||||
context: Cxt,
|
||||
option: OP
|
||||
) {
|
||||
) {
|
||||
const { data, action, id: operId, filter } = operation;
|
||||
const now = Date.now();
|
||||
|
||||
|
|
@ -1268,13 +1268,13 @@ judgeRelation(entity: keyof ED, attr: string) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private doUpdateSingleRow<T extends keyof ED, OP extends OperateOption, Cxt extends SyncContext<ED>>(entity: T,
|
||||
operation: ED[T]['Operation'],
|
||||
context: Cxt,
|
||||
option: OP
|
||||
) {
|
||||
) {
|
||||
const { data, action, id: operId, filter } = operation;
|
||||
const now = Date.now();
|
||||
|
||||
|
|
@ -1337,21 +1337,21 @@ judgeRelation(entity: keyof ED, attr: string) {
|
|||
return this.updateAbjointRow(entity, operation, context, option);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected cascadeUpdate<T extends keyof ED, Cxt extends SyncContext<ED>, OP extends OperateOption>(
|
||||
entity: T,
|
||||
operation: ED[T]['Operation'],
|
||||
context: Cxt,
|
||||
option: OP): OperationResult < ED > {
|
||||
option: OP): OperationResult<ED> {
|
||||
reinforceOperation(this.getSchema(), entity, operation);
|
||||
const { action, data, filter, id } = operation;
|
||||
let opData: any;
|
||||
const wholeBeforeFns: Array<() => any> =[];
|
||||
const wholeAfterFns: Array<() => any> = [];
|
||||
const result: OperationResult<ED> = {};
|
||||
const wholeBeforeFns: Array<() => any> = [];
|
||||
const wholeAfterFns: Array<() => any> = [];
|
||||
const result: OperationResult<ED> = {};
|
||||
|
||||
if (['create', 'create-l'].includes(action) && data instanceof Array) {
|
||||
if (['create', 'create-l'].includes(action) && data instanceof Array) {
|
||||
opData = [];
|
||||
for (const d of data) {
|
||||
const { data: od, beforeFns, afterFns } = this.destructCascadeUpdate(
|
||||
|
|
@ -1366,8 +1366,8 @@ if (['create', 'create-l'].includes(action) && data instanceof Array) {
|
|||
wholeBeforeFns.push(...beforeFns);
|
||||
wholeAfterFns.push(...afterFns);
|
||||
}
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
const { data: od, beforeFns, afterFns } = this.destructCascadeUpdate(
|
||||
entity,
|
||||
action,
|
||||
|
|
@ -1380,21 +1380,21 @@ else {
|
|||
opData = od;
|
||||
wholeBeforeFns.push(...beforeFns);
|
||||
wholeAfterFns.push(...afterFns);
|
||||
}
|
||||
}
|
||||
|
||||
const operation2: ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'] =
|
||||
const operation2: ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'] =
|
||||
Object.assign({}, operation as ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'], {
|
||||
data: opData as ED[T]['OpSchema'],
|
||||
});
|
||||
|
||||
for (const before of wholeBeforeFns) {
|
||||
for (const before of wholeBeforeFns) {
|
||||
before();
|
||||
}
|
||||
const count = this.doUpdateSingleRow(entity, operation2, context, option);
|
||||
for (const after of wholeAfterFns) {
|
||||
}
|
||||
const count = this.doUpdateSingleRow(entity, operation2, context, option);
|
||||
for (const after of wholeAfterFns) {
|
||||
after();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1408,15 +1408,15 @@ return result;
|
|||
entity: T,
|
||||
operation: ED[T]['Operation'],
|
||||
context: Cxt,
|
||||
option: OP): Promise < OperationResult < ED >> {
|
||||
option: OP): Promise<OperationResult<ED>> {
|
||||
reinforceOperation(this.getSchema(), entity, operation);
|
||||
const { action, data, filter, id } = operation;
|
||||
let opData: any;
|
||||
const wholeBeforeFns: Array<() => Promise<any>> =[];
|
||||
const wholeAfterFns: Array<() => Promise<any>> = [];
|
||||
const result: OperationResult<ED> = {};
|
||||
const wholeBeforeFns: Array<() => Promise<any>> = [];
|
||||
const wholeAfterFns: Array<() => Promise<any>> = [];
|
||||
const result: OperationResult<ED> = {};
|
||||
|
||||
if (['create', 'create-l'].includes(action) && data instanceof Array) {
|
||||
if (['create', 'create-l'].includes(action) && data instanceof Array) {
|
||||
opData = [];
|
||||
for (const d of data) {
|
||||
const { data: od, beforeFns, afterFns } = this.destructCascadeUpdate(
|
||||
|
|
@ -1431,8 +1431,8 @@ if (['create', 'create-l'].includes(action) && data instanceof Array) {
|
|||
wholeBeforeFns.push(...beforeFns);
|
||||
wholeAfterFns.push(...afterFns);
|
||||
}
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
const { data: od, beforeFns, afterFns } = this.destructCascadeUpdate(
|
||||
entity,
|
||||
action,
|
||||
|
|
@ -1445,33 +1445,33 @@ else {
|
|||
opData = od;
|
||||
wholeBeforeFns.push(...beforeFns);
|
||||
wholeAfterFns.push(...afterFns);
|
||||
}
|
||||
}
|
||||
|
||||
const operation2: ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'] =
|
||||
const operation2: ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'] =
|
||||
Object.assign({}, operation as ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'], {
|
||||
data: opData as ED[T]['OpSchema'],
|
||||
});
|
||||
|
||||
for (const before of wholeBeforeFns) {
|
||||
for (const before of wholeBeforeFns) {
|
||||
await before();
|
||||
}
|
||||
const count = await this.doUpdateSingleRowAsync(entity, operation2, context, option);
|
||||
this.mergeOperationResult(result, {
|
||||
}
|
||||
const count = await this.doUpdateSingleRowAsync(entity, operation2, context, option);
|
||||
this.mergeOperationResult(result, {
|
||||
[entity]: {
|
||||
[operation2.action]: count,
|
||||
}
|
||||
} as OperationResult<ED>);
|
||||
for (const after of wholeAfterFns) {
|
||||
} as OperationResult<ED>);
|
||||
for (const after of wholeAfterFns) {
|
||||
await after();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected cascadeSelect<T extends keyof ED, OP extends SelectOption, Cxt extends SyncContext<ED>>(
|
||||
entity: T,
|
||||
selection: ED[T]['Selection'],
|
||||
context: Cxt,
|
||||
option: OP): Partial < ED[T]['Schema'] > [] {
|
||||
option: OP): Partial<ED[T]['Schema']>[] {
|
||||
reinforceSelection(this.getSchema(), entity, selection);
|
||||
const { data, filter, indexFrom, count, sorter } = selection;
|
||||
const { projection, cascadeSelectionFns } = this.destructCascadeSelect(
|
||||
|
|
@ -1519,7 +1519,7 @@ return result;
|
|||
}
|
||||
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将一次查询的结果集加入result
|
||||
|
|
@ -1528,7 +1528,7 @@ return result;
|
|||
* @param rows
|
||||
* @param context
|
||||
*/
|
||||
private addToResultSelections<T extends keyof ED, Cxt extends AsyncContext<ED>>(entity: T, rows: Partial < ED[T]['Schema'] > [], context: Cxt) {
|
||||
private addToResultSelections<T extends keyof ED, Cxt extends AsyncContext<ED>>(entity: T, rows: Partial<ED[T]['Schema']>[], context: Cxt) {
|
||||
if (this.supportManyToOneJoin()) {
|
||||
const attrsToPick: string[] = [];
|
||||
for (const attr in rows[0]) {
|
||||
|
|
@ -1555,9 +1555,9 @@ return result;
|
|||
else {
|
||||
this.addSingleRowToResultSelections(entity, rows, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private addSingleRowToResultSelections<T extends keyof ED, Cxt extends AsyncContext<ED>>(entity: T, rows: Partial < ED[T]['OpSchema'] > [], context: Cxt) {
|
||||
private addSingleRowToResultSelections<T extends keyof ED, Cxt extends AsyncContext<ED>>(entity: T, rows: Partial<ED[T]['OpSchema']>[], context: Cxt) {
|
||||
const { opRecords } = context;
|
||||
|
||||
let lastOperation = opRecords[opRecords.length - 1];
|
||||
|
|
@ -1605,13 +1605,13 @@ return result;
|
|||
Object.assign(lastOperation.d, {
|
||||
[entity]: entityBranch,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected async cascadeSelectAsync<T extends keyof ED, OP extends SelectOption, Cxt extends AsyncContext<ED>>(
|
||||
entity: T,
|
||||
selection: ED[T]['Selection'],
|
||||
context: Cxt,
|
||||
option: OP): Promise < Partial < ED[T]['Schema'] > [] > {
|
||||
option: OP): Promise<Partial<ED[T]['Schema']>[]> {
|
||||
reinforceSelection(this.getSchema(), entity, selection);
|
||||
const { data, filter, indexFrom, count, sorter } = selection;
|
||||
const { projection, cascadeSelectionFns } = this.destructCascadeSelect(
|
||||
|
|
@ -1631,11 +1631,11 @@ return result;
|
|||
}, context, option);
|
||||
|
||||
|
||||
if(!option.dontCollect) {
|
||||
if (!option.dontCollect) {
|
||||
this.addToResultSelections(entity, rows, context);
|
||||
}
|
||||
}
|
||||
|
||||
if (cascadeSelectionFns.length > 0) {
|
||||
if (cascadeSelectionFns.length > 0) {
|
||||
const ruException: Array<{
|
||||
entity: keyof ED,
|
||||
selection: ED[keyof ED]['Selection']
|
||||
|
|
@ -1662,8 +1662,8 @@ if (cascadeSelectionFns.length > 0) {
|
|||
if (ruException.length > 0) {
|
||||
throw new OakRowUnexistedException(ruException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rows;
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
|
|
@ -335,7 +335,7 @@ function translateCascadeRelationFilterMaker<ED extends EntityDict & BaseEntityD
|
|||
const getForeignKeyId = (d: ED[keyof ED]['CreateSingle']['data']) => {
|
||||
if (relation === 2) {
|
||||
if (d.entity === attr && typeof d.entityId === 'string') {
|
||||
return d.entitId as string;
|
||||
return d.entityId as string;
|
||||
}
|
||||
throw new OakUserUnpermittedException();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue