Skip to content

Commit eba4da3

Browse files
authored
chore: add whitespace (#120)
this adds some newlines for readability, and wraps return statements in curly blocks.
1 parent e82f8e1 commit eba4da3

File tree

8 files changed

+126
-84
lines changed

8 files changed

+126
-84
lines changed

apps/knowledge-base/lib/data/content-blocks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export async function getContentBlockTypes() {
1111
type: true,
1212
},
1313
});
14+
1415
return contentBlockTypes;
1516
}
1617

@@ -20,6 +21,7 @@ export async function getContentBlockByType(type: ContentBlockTypes["type"]) {
2021
type,
2122
},
2223
});
24+
2325
return contentBlockType;
2426
}
2527

@@ -33,9 +35,11 @@ interface CreateContentBlocksParams {
3335

3436
export async function createContentBlocks(params: CreateContentBlocksParams) {
3537
const { data } = params;
38+
3639
const contentBlockIds = await db.insert(schema.contentBlocks).values(data).returning({
3740
id: schema.contentBlocks.id,
3841
typeId: schema.contentBlocks.typeId,
3942
});
43+
4044
return contentBlockIds;
4145
}

apps/knowledge-base/lib/data/entities.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ interface CreateEntitiesParams {
1515

1616
export async function createEntities(params: CreateEntitiesParams) {
1717
const { data } = params;
18+
1819
const entityIds = await db.insert(schema.entities).values(data).returning({
1920
id: schema.entities.id,
2021
});
22+
2123
return entityIds;
2224
}

apps/knowledge-base/lib/data/events.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
22

33
import { count, eq } from "@dariah-eric/database";
4-
import { db, type Transaction } from "@dariah-eric/database/client";
4+
import { db } from "@dariah-eric/database/client";
55
import * as schema from "@dariah-eric/database/schema";
66
import { client } from "@dariah-eric/images/client";
77

@@ -102,18 +102,20 @@ interface CreateEventParams extends Omit<schema.EventInput, "id" | "createdAt" |
102102
slug: string;
103103
resourceIds?: Array<string>;
104104
}
105+
105106
export async function createEvent(params: CreateEventParams) {
106107
const { duration, imageId, isFullDay, location, slug, summary, title, website } = params;
107108

108-
const entityType =
109-
(await db.query.entityTypes.findFirst({
110-
columns: {
111-
id: true,
112-
},
113-
where: { type: "events" },
114-
})) ?? undefined;
109+
const entityType = await db.query.entityTypes.findFirst({
110+
columns: {
111+
id: true,
112+
},
113+
where: { type: "events" },
114+
});
115115

116-
if (!entityType) return;
116+
if (entityType == null) {
117+
return null;
118+
}
117119

118120
const entityStatus = await db.query.entityStatus.findFirst({
119121
columns: {
@@ -122,24 +124,27 @@ export async function createEvent(params: CreateEventParams) {
122124
where: { type: "draft" },
123125
});
124126

125-
if (!entityStatus) return;
127+
if (entityStatus == null) {
128+
return null;
129+
}
126130

127-
const entityId = await db.transaction(async (tx: Transaction) => {
128-
const entityIds = await tx
131+
const entityId = await db.transaction(async (tx) => {
132+
const [item] = await tx
129133
.insert(schema.entities)
130134
.values({
131135
typeId: entityType.id,
132-
documentId: undefined,
133136
statusId: entityStatus.id,
134137
slug,
135138
})
136139
.returning({
137140
id: schema.entities.id,
138141
});
139142

140-
if (!entityIds[0]) return tx.rollback();
143+
if (item == null) {
144+
return tx.rollback();
145+
}
141146

142-
const { id } = entityIds[0];
147+
const { id } = item;
143148

144149
const event = {
145150
id,
@@ -151,6 +156,7 @@ export async function createEvent(params: CreateEventParams) {
151156
isFullDay,
152157
website,
153158
};
159+
154160
await tx.insert(schema.events).values(event);
155161

156162
const fieldNamesIds = await tx.query.entityTypesFieldsNames.findMany({
@@ -169,7 +175,7 @@ export async function createEvent(params: CreateEventParams) {
169175

170176
return id;
171177
});
172-
// decide, what we need to return here
178+
173179
return {
174180
entityId,
175181
};

apps/knowledge-base/lib/data/impact-case-studies.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,20 @@ interface CreateImpactCaseStudyParams extends Omit<
105105
slug: string;
106106
resourceIds?: Array<string>;
107107
}
108+
108109
export async function createImpactCaseStudy(params: CreateImpactCaseStudyParams) {
109110
const { imageId, slug, summary, title } = params;
110111

111-
const entityType =
112-
(await db.query.entityTypes.findFirst({
113-
columns: {
114-
id: true,
115-
},
116-
where: { type: "impact_case_studies" },
117-
})) ?? undefined;
112+
const entityType = await db.query.entityTypes.findFirst({
113+
columns: {
114+
id: true,
115+
},
116+
where: { type: "impact_case_studies" },
117+
});
118118

119-
if (!entityType) return;
119+
if (entityType == null) {
120+
return;
121+
}
120122

121123
const entityStatus = await db.query.entityStatus.findFirst({
122124
columns: {
@@ -125,24 +127,27 @@ export async function createImpactCaseStudy(params: CreateImpactCaseStudyParams)
125127
where: { type: "draft" },
126128
});
127129

128-
if (!entityStatus) return;
130+
if (entityStatus == null) {
131+
return;
132+
}
129133

130134
const entityId = await db.transaction(async (tx) => {
131-
const entityIds = await tx
135+
const [item] = await tx
132136
.insert(schema.entities)
133137
.values({
134138
typeId: entityType.id,
135-
documentId: undefined,
136139
statusId: entityStatus.id,
137140
slug,
138141
})
139142
.returning({
140143
id: schema.entities.id,
141144
});
142145

143-
if (!entityIds[0]) return tx.rollback();
146+
if (item == null) {
147+
return tx.rollback();
148+
}
144149

145-
const { id } = entityIds[0];
150+
const { id } = item;
146151

147152
const impactCaseStudy = {
148153
id,
@@ -151,6 +156,7 @@ export async function createImpactCaseStudy(params: CreateImpactCaseStudyParams)
151156
imageId,
152157
location,
153158
};
159+
154160
await tx.insert(schema.impactCaseStudies).values(impactCaseStudy);
155161

156162
const fieldNamesIds = await tx.query.entityTypesFieldsNames.findMany({
@@ -170,7 +176,6 @@ export async function createImpactCaseStudy(params: CreateImpactCaseStudyParams)
170176
return id;
171177
});
172178

173-
// decide, what we need to return here
174179
return {
175180
entityId,
176181
};

apps/knowledge-base/lib/data/news.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,20 @@ interface CreateNewsItemParams extends Omit<
105105
slug: string;
106106
resourceIds?: Array<string>;
107107
}
108+
108109
export async function createNewsItem(params: CreateNewsItemParams) {
109110
const { imageId, slug, summary, title } = params;
110111

111-
const entityType =
112-
(await db.query.entityTypes.findFirst({
113-
columns: {
114-
id: true,
115-
},
116-
where: { type: "news" },
117-
})) ?? undefined;
112+
const entityType = await db.query.entityTypes.findFirst({
113+
columns: {
114+
id: true,
115+
},
116+
where: { type: "news" },
117+
});
118118

119-
if (!entityType) return;
119+
if (entityType == null) {
120+
return null;
121+
}
120122

121123
const entityStatus = await db.query.entityStatus.findFirst({
122124
columns: {
@@ -125,10 +127,12 @@ export async function createNewsItem(params: CreateNewsItemParams) {
125127
where: { type: "draft" },
126128
});
127129

128-
if (!entityStatus) return;
130+
if (entityStatus == null) {
131+
return null;
132+
}
129133

130134
const entityId = await db.transaction(async (tx) => {
131-
const entityIds = await tx
135+
const [item] = await tx
132136
.insert(schema.entities)
133137
.values({
134138
typeId: entityType.id,
@@ -140,16 +144,19 @@ export async function createNewsItem(params: CreateNewsItemParams) {
140144
id: schema.entities.id,
141145
});
142146

143-
if (!entityIds[0]) return tx.rollback();
147+
if (item == null) {
148+
return tx.rollback();
149+
}
144150

145-
const { id } = entityIds[0];
151+
const { id } = item;
146152

147153
const newsItem = {
148154
id,
149155
title,
150156
summary,
151157
imageId,
152158
};
159+
153160
await tx.insert(schema.news).values(newsItem);
154161

155162
const fieldNamesIds = await tx.query.entityTypesFieldsNames.findMany({
@@ -169,7 +176,6 @@ export async function createNewsItem(params: CreateNewsItemParams) {
169176
return id;
170177
});
171178

172-
// decide, what we need to return here
173179
return {
174180
entityId,
175181
};

apps/knowledge-base/lib/data/organisational-units.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
22

33
import { count, eq } from "@dariah-eric/database";
4-
import { db, type Transaction } from "@dariah-eric/database/client";
4+
import { db } from "@dariah-eric/database/client";
55
import * as schema from "@dariah-eric/database/schema";
66
import { client } from "@dariah-eric/images/client";
77

@@ -107,18 +107,20 @@ interface CreateOrganisationalUnitParams extends Omit<
107107
slug: string;
108108
resourceIds?: Array<string>;
109109
}
110+
110111
export async function createOrganisationalUnit(params: CreateOrganisationalUnitParams) {
111112
const { imageId, metadata, name, slug, summary, typeId } = params;
112113

113-
const entityType =
114-
(await db.query.entityTypes.findFirst({
115-
columns: {
116-
id: true,
117-
},
118-
where: { type: "organisational_units" },
119-
})) ?? undefined;
114+
const entityType = await db.query.entityTypes.findFirst({
115+
columns: {
116+
id: true,
117+
},
118+
where: { type: "organisational_units" },
119+
});
120120

121-
if (!entityType) return;
121+
if (entityType == null) {
122+
return null;
123+
}
122124

123125
const entityStatus = await db.query.entityStatus.findFirst({
124126
columns: {
@@ -127,10 +129,12 @@ export async function createOrganisationalUnit(params: CreateOrganisationalUnitP
127129
where: { type: "draft" },
128130
});
129131

130-
if (!entityStatus) return;
132+
if (entityStatus == null) {
133+
return null;
134+
}
131135

132-
const entityId = await db.transaction(async (tx: Transaction) => {
133-
const entityIds = await tx
136+
const entityId = await db.transaction(async (tx) => {
137+
const [item] = await tx
134138
.insert(schema.entities)
135139
.values({
136140
typeId: entityType.id,
@@ -142,9 +146,11 @@ export async function createOrganisationalUnit(params: CreateOrganisationalUnitP
142146
id: schema.entities.id,
143147
});
144148

145-
if (!entityIds[0]) return tx.rollback();
149+
if (item == null) {
150+
return tx.rollback();
151+
}
146152

147-
const { id } = entityIds[0];
153+
const { id } = item;
148154

149155
const organisationalUnit = {
150156
id,
@@ -154,6 +160,7 @@ export async function createOrganisationalUnit(params: CreateOrganisationalUnitP
154160
imageId,
155161
typeId,
156162
};
163+
157164
await tx.insert(schema.organisationalUnits).values(organisationalUnit);
158165

159166
const fieldNamesIds = await tx.query.entityTypesFieldsNames.findMany({
@@ -172,7 +179,7 @@ export async function createOrganisationalUnit(params: CreateOrganisationalUnitP
172179

173180
return id;
174181
});
175-
// decide, what we need to return here
182+
176183
return {
177184
entityId,
178185
};

0 commit comments

Comments
 (0)