|
|
@@ -144,6 +144,12 @@ export class TestEntity extends VendureEntity implements Translatable, HasCustom
|
|
|
|
|
|
@Column(() => TestEntityCustomFields)
|
|
|
customFields: TestEntityCustomFields;
|
|
|
+
|
|
|
+ @ManyToOne(() => TestEntity, (type) => type.parent)
|
|
|
+ parent: TestEntity | null;
|
|
|
+
|
|
|
+ @Column('int', { nullable: true })
|
|
|
+ parentId: ID | null;
|
|
|
}
|
|
|
|
|
|
@Entity()
|
|
|
@@ -188,6 +194,7 @@ export class ListQueryResolver {
|
|
|
.build(TestEntity, args.options, {
|
|
|
ctx,
|
|
|
relations: [
|
|
|
+ 'parent',
|
|
|
'orderRelation',
|
|
|
'orderRelation.customer',
|
|
|
'customFields.relation',
|
|
|
@@ -206,7 +213,7 @@ export class ListQueryResolver {
|
|
|
}
|
|
|
}
|
|
|
return {
|
|
|
- items: items.map(i => translateDeep(i, ctx.languageCode)),
|
|
|
+ items: items.map(i => translateDeep(i, ctx.languageCode, ['parent'])),
|
|
|
totalItems,
|
|
|
};
|
|
|
});
|
|
|
@@ -215,7 +222,7 @@ export class ListQueryResolver {
|
|
|
@Query()
|
|
|
testEntitiesGetMany(@Ctx() ctx: RequestContext, @Args() args: any) {
|
|
|
return this.listQueryBuilder
|
|
|
- .build(TestEntity, args.options, { ctx, relations: ['prices'] })
|
|
|
+ .build(TestEntity, args.options, { ctx, relations: ['prices', 'parent'] })
|
|
|
.getMany()
|
|
|
.then(items => {
|
|
|
for (const item of items) {
|
|
|
@@ -224,7 +231,7 @@ export class ListQueryResolver {
|
|
|
item.activePrice = item.prices.find(p => p.channelId === 1)!.price;
|
|
|
}
|
|
|
}
|
|
|
- return items.map(i => translateDeep(i, ctx.languageCode));
|
|
|
+ return items.map(i => translateDeep(i, ctx.languageCode, ['parent']));
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
@@ -274,6 +281,7 @@ const apiExtensions = gql`
|
|
|
nullableId: ID
|
|
|
nullableDate: DateTime
|
|
|
customFields: TestEntityCustomFields!
|
|
|
+ parent: TestEntity
|
|
|
}
|
|
|
|
|
|
type TestEntityList implements PaginatedList {
|
|
|
@@ -324,9 +332,9 @@ export class ListQueryPlugin implements OnApplicationBootstrap {
|
|
|
) {}
|
|
|
|
|
|
async onApplicationBootstrap() {
|
|
|
- const count = await this.connection.getRepository(TestEntity).count();
|
|
|
+ const count = await this.connection.rawConnection.getRepository(TestEntity).count();
|
|
|
if (count === 0) {
|
|
|
- const testEntities = await this.connection.getRepository(TestEntity).save([
|
|
|
+ const testEntities = await this.connection.rawConnection.getRepository(TestEntity).save([
|
|
|
new TestEntity({
|
|
|
label: 'A',
|
|
|
description: 'Lorem ipsum', // 11
|
|
|
@@ -392,6 +400,11 @@ export class ListQueryPlugin implements OnApplicationBootstrap {
|
|
|
}),
|
|
|
]);
|
|
|
|
|
|
+ // test entity with self-referencing relation without tree structure decorator
|
|
|
+ testEntities[0].parent = testEntities[1];
|
|
|
+ testEntities[3].parent = testEntities[1];
|
|
|
+ await this.connection.rawConnection.getRepository(TestEntity).save([testEntities[0], testEntities[3]]);
|
|
|
+
|
|
|
const translations: any = {
|
|
|
A: { [LanguageCode.en]: 'apple', [LanguageCode.de]: 'apfel' },
|
|
|
B: { [LanguageCode.en]: 'bike', [LanguageCode.de]: 'fahrrad' },
|
|
|
@@ -408,7 +421,7 @@ export class ListQueryPlugin implements OnApplicationBootstrap {
|
|
|
};
|
|
|
|
|
|
for (const testEntity of testEntities) {
|
|
|
- await this.connection.getRepository(TestEntityPrice).save([
|
|
|
+ await this.connection.rawConnection.getRepository(TestEntityPrice).save([
|
|
|
new TestEntityPrice({
|
|
|
price: testEntity.description.length,
|
|
|
channelId: 1,
|
|
|
@@ -424,7 +437,7 @@ export class ListQueryPlugin implements OnApplicationBootstrap {
|
|
|
for (const code of [LanguageCode.en, LanguageCode.de]) {
|
|
|
const translation = translations[testEntity.label][code];
|
|
|
if (translation) {
|
|
|
- await this.connection.getRepository(TestEntityTranslation).save(
|
|
|
+ await this.connection.rawConnection.getRepository(TestEntityTranslation).save(
|
|
|
new TestEntityTranslation({
|
|
|
name: translation,
|
|
|
base: testEntity,
|
|
|
@@ -436,13 +449,13 @@ export class ListQueryPlugin implements OnApplicationBootstrap {
|
|
|
|
|
|
if (nestedData[testEntity.label]) {
|
|
|
for (const nestedContent of nestedData[testEntity.label]) {
|
|
|
- await this.connection.getRepository(CustomFieldRelationTestEntity).save(
|
|
|
+ await this.connection.rawConnection.getRepository(CustomFieldRelationTestEntity).save(
|
|
|
new CustomFieldRelationTestEntity({
|
|
|
parent: testEntity,
|
|
|
data: nestedContent.data,
|
|
|
}),
|
|
|
);
|
|
|
- await this.connection.getRepository(CustomFieldOtherRelationTestEntity).save(
|
|
|
+ await this.connection.rawConnection.getRepository(CustomFieldOtherRelationTestEntity).save(
|
|
|
new CustomFieldOtherRelationTestEntity({
|
|
|
parent: testEntity,
|
|
|
data: nestedContent.data,
|
|
|
@@ -452,7 +465,7 @@ export class ListQueryPlugin implements OnApplicationBootstrap {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- const testEntities = await this.connection.getRepository(TestEntity).find();
|
|
|
+ const testEntities = await this.connection.rawConnection.getRepository(TestEntity).find();
|
|
|
const ctx = await this.requestContextService.create({ apiType: 'admin' });
|
|
|
const customers = await this.connection.rawConnection.getRepository(Customer).find();
|
|
|
let i = 0;
|
|
|
@@ -463,7 +476,7 @@ export class ListQueryPlugin implements OnApplicationBootstrap {
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
const order = await this.orderService.create(ctx, customer.user!.id);
|
|
|
testEntity.orderRelation = order;
|
|
|
- await this.connection.getRepository(TestEntity).save(testEntity);
|
|
|
+ await this.connection.rawConnection.getRepository(TestEntity).save(testEntity);
|
|
|
} catch (e: any) {
|
|
|
Logger.error(e);
|
|
|
}
|