Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 0 additions & 57 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/backend/services/resource_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
ResourceBundle,
ResourceIndexItem,
ResourcePayload,
ResourceStoryUsage,
ResourceUsage,
TextBundle,
VideoBundle,
} from '../../types.js';
Expand Down Expand Up @@ -64,7 +64,7 @@ export class ResourceService {
return models.map((model) => this.toResourceItem(model));
}

public async countStoryUsagesByLocale(locale: string): Promise<Map<string, number>> {
async usageCountForLocale(locale: string): Promise<Map<string, number>> {
const localisations = await StoryLocalisation.query()
.where('locale', locale)
.select('resources');
Expand All @@ -82,7 +82,7 @@ export class ResourceService {

public async listIndexItems(locale: string): Promise<ResourceIndexItem[]> {
const models = await Resource.query().where('locale', locale).orderBy('title', 'asc');
const usageCounts = await this.countStoryUsagesByLocale(locale);
const usageCounts = await this.usageCountForLocale(locale);

return models.map((model) => ({
...this.toIndexItem(model),
Expand Down Expand Up @@ -162,17 +162,17 @@ export class ResourceService {
});
}

public async listStoryUsages(
public async storyUsageFor(
resourceId: string,
locale: string,
): Promise<ResourceStoryUsage[]> {
): Promise<ResourceUsage[]> {
const localisations = await StoryLocalisation.query()
.where('locale', locale)
.whereRaw('resources @> ?::jsonb', [JSON.stringify([resourceId])])
.orderBy('title', 'asc');

return localisations.map((localisation) => ({
storyId: localisation.storyId,
id: localisation.storyId,
title: localisation.title,
}));
}
Expand Down
12 changes: 6 additions & 6 deletions src/backend/services/story_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export class StoryService {
return props;
}

public async buildUpdatePayload(
public async updatePayloadFor(
storyId: number,
locale: string,
): Promise<StoryUpdatePayload | undefined> {
Expand Down Expand Up @@ -256,13 +256,13 @@ export class StoryService {
};
}

public async prepSections(
public async preppedSections(
version: StoryVersion,
sections?: PostedSection[],
): Promise<StorySection[]> {
if (!sections) return [];
const sourceLocale = this.config.languages[0].locale;
if (version.locale === sourceLocale) return this.sourceSections(sections);
if (version.locale === sourceLocale) return this.indexedSections(sections);

const sourceLocalisation = await StoryLocalisation.query()
.where('storyId', version.storyId)
Expand All @@ -282,7 +282,7 @@ export class StoryService {
});
}

sourceSections(sections: PostedSection[]): StorySection[] {
public indexedSections(sections: PostedSection[]): StorySection[] {
return sections.map((section) => {
return {
id: section.id?.trim() ? section.id : randomUUID(),
Expand Down Expand Up @@ -465,7 +465,7 @@ export class StoryService {
};
}

private formatBespokeTemplateForDisplay(template: BundleTemplate): BundleTemplate {
private templateItemForPicklist(template: BundleTemplate): BundleTemplate {
return {
...template,
name: template.name.endsWith(' (custom)')
Expand All @@ -477,7 +477,7 @@ export class StoryService {
private templatesForEditDisplay(): BundleTemplate[] {
return [
...this.config.bespokeTemplates.map((template) =>
this.formatBespokeTemplateForDisplay(template),
this.templateItemForPicklist(template),
),
...this.config.storyTemplates,
];
Expand Down
2 changes: 1 addition & 1 deletion src/backend/stubs/controllers/resources_controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class ResourcesController {
return ctx.inertia.render('ResourceNotFound', {});
}

const usedInStories = await service.listStoryUsages(model.id, version.locale);
const usedInStories = await service.storyUsageFor(model.id, version.locale);

const props: ResourceEditProps = {
providers,
Expand Down
6 changes: 3 additions & 3 deletions src/backend/stubs/controllers/stories_controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default class StoriesController {
coverImage: payload.coverImage,
description: payload.description,
tags: payload.tags,
sections: storyService.sourceSections(payload.sections ?? []),
sections: storyService.indexedSections(payload.sections ?? []),
resources: payload.resources ?? [],
});
local.useTransaction(trx);
Expand Down Expand Up @@ -160,7 +160,7 @@ export default class StoriesController {
if (story === undefined) return ctx.response.notFound();
if (story.isPublished) return ctx.response.redirect().back();

const payload = await storyService.buildUpdatePayload(version.storyId, version.locale);
const payload = await storyService.updatePayloadFor(version.storyId, version.locale);
if (!payload) return ctx.response.notFound();

payload.isPublished = true;
Expand Down Expand Up @@ -208,7 +208,7 @@ export default class StoriesController {
resources?: string[];
},
) {
const sections = await storyService.prepSections(version, payload.sections);
const sections = await storyService.preppedSections(version, payload.sections);

await db.transaction(async (trx) => {
// update the story if it's the source locale
Expand Down
4 changes: 2 additions & 2 deletions src/backend/stubs/tests/unit/resource_service.stub
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ test.group('Resource service', (group) => {
assert.equal(unattachedItem?.usedInCount, 0);
});

test('listStoryUsages returns stories in locale ordered by title', async ({ assert }) => {
test('storyUsageFor returns stories in locale ordered by title', async ({ assert }) => {
const resource = await ResourceFactory.merge({ locale: 'en' }).create();

const alphaStory = await StoryFactory.with('localisations').create();
Expand All @@ -143,7 +143,7 @@ test.group('Resource service', (group) => {
await otherLocaleLocalisation.save();

const service = new ResourceService();
const usages = await service.listStoryUsages(resource.id, 'en');
const usages = await service.storyUsageFor(resource.id, 'en');

assert.lengthOf(usages, 2);
assert.deepEqual(usages, [
Expand Down
Loading
Loading