Skip to content

Commit

Permalink
chore: mark form entry for create record (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
tea-artist committed Jun 13, 2024
1 parent 1117e8c commit ab43e4d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,16 @@ export class EventEmitterService {

private createExtendPlainContext(docId: string, id: string) {
const user = this.cls.get('user');
const entry = this.cls.get('entry');
return {
baseId: docId,
tableId: docId,
viewId: id,
fieldId: id,
recordId: id,
context: {
user: user,
user,
entry,
},
};
}
Expand Down
4 changes: 4 additions & 0 deletions apps/nestjs-backend/src/event-emitter/events/core-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export interface IEventContext {
name: string;
email: string;
};
entry?: {
type: string;
id: string;
};
headers?: Record<string, string | undefined> | IncomingHttpHeaders;
opMeta?: {
name: OpName;
Expand Down
4 changes: 4 additions & 0 deletions apps/nestjs-backend/src/features/share/share.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import type {
import { Knex } from 'knex';
import { isEmpty, pick } from 'lodash';
import { InjectModel } from 'nest-knexjs';
import { ClsService } from 'nestjs-cls';
import { InjectDbProvider } from '../../db-provider/db.provider';
import { IDbProvider } from '../../db-provider/db.provider.interface';
import type { IClsStore } from '../../types/cls';
import { getFullStorageUrl } from '../../utils/full-storage-url';
import { isNotHiddenField } from '../../utils/is-not-hidden-field';
import { AggregationService } from '../aggregation/aggregation.service';
Expand Down Expand Up @@ -66,6 +68,7 @@ export class ShareService {
private readonly recordOpenApiService: RecordOpenApiService,
private readonly selectionService: SelectionService,
private readonly collaboratorService: CollaboratorService,
private readonly cls: ClsService<IClsStore>,
@InjectDbProvider() private readonly dbProvider: IDbProvider,
@InjectModel('CUSTOM_KNEX') private readonly knex: Knex
) {}
Expand Down Expand Up @@ -165,6 +168,7 @@ export class ShareService {
}

const { records } = await this.prismaService.$tx(async () => {
this.cls.set('entry', { type: 'form', id: view.id });
return await this.recordOpenApiService.createRecords(tableId, {
records: [{ fields }],
fieldKeyType: FieldKeyType.Id,
Expand Down
5 changes: 0 additions & 5 deletions apps/nestjs-backend/src/share-db/share-db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,9 @@ export class ShareDbService extends ShareDBClass {
// broadcast raw op events to client
this.prismaService.bindAfterTransaction(() => {
const rawOpMaps = this.cls.get('tx.rawOpMaps');
const stashOpMap = this.cls.get('tx.stashOpMap');
this.cls.set('tx.rawOpMaps', undefined);
this.cls.set('tx.stashOpMap', undefined);

const ops: IRawOpMap[] = [];
if (stashOpMap) {
ops.push(stashOpMap);
}
if (rawOpMaps?.length) {
ops.push(...rawOpMaps);
}
Expand Down
5 changes: 4 additions & 1 deletion apps/nestjs-backend/src/types/cls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ export interface IClsStore extends ClsStore {
email: string;
};
accessTokenId?: string;
entry?: {
type: string;
id: string;
};
tx: {
client?: Prisma.TransactionClient;
timeStr?: string;
id?: string;
rawOpMaps?: IRawOpMap[];
stashOpMap?: IRawOpMap;
};
shareViewId?: string;
permissions: PermissionAction[];
Expand Down

0 comments on commit ab43e4d

Please sign in to comment.