Skip to content

Commit

Permalink
replace lastCharCode with nextCharCode
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Jun 16, 2024
1 parent d261156 commit d979a1c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/v2/interfaces/uses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface UseRepository {
getUsesByIdsAndEdition(idArr: number[], edition: GalleryEdition): Promise<Uses>;
getRaw(): Promise<Record<string, Use>>;
getUseByIdOrName(idOrName: string): Promise<Uses | Use>;
lastCharCode(textureID: string): Promise<number>;
nextCharCode(textureID: string): Promise<number>;
deleteUse(id: string): Promise<WriteConfirmation[]>;
set(use: Use): Promise<Use>;
setMultiple(uses: Uses): Promise<Uses>;
Expand Down
6 changes: 3 additions & 3 deletions src/v2/repository/use.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class UseFirestormRepository implements UseRepository {
);
}

async lastCharCode(textureID: string): Promise<number> {
async nextCharCode(textureID: string): Promise<number> {
const foundUses = await uses.search([
{
field: "texture",
Expand All @@ -58,8 +58,8 @@ export default class UseFirestormRepository implements UseRepository {

if (curCode > best) return curCode;
return best;
}, // subtract one since we're adding one later
"a".charCodeAt(0) - 1,
}, // start at a and work upwards
"a".charCodeAt(0),
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/v2/service/use.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export default class UseService {
}

async appendUse(textureID: string, use: EntireUseToCreate): Promise<void> {
const lastCharCode = await this.repo.lastCharCode(textureID);
const nextLetter = String.fromCharCode(lastCharCode + 1);
const nextCharCode = await this.repo.nextCharCode(textureID);
const nextLetter = String.fromCharCode(nextCharCode);
const newUseID = `${textureID}${nextLetter}`;
const pathsWithUse: InputPath[] = use.paths.map((p) => ({ ...p, use: newUseID }));

Expand All @@ -92,11 +92,11 @@ export default class UseService {
}

async appendMultipleUses(textureID: string, uses: EntireUseToCreate[]): Promise<void> {
const lastCharCode = await this.repo.lastCharCode(textureID);
const nextCharCode = await this.repo.nextCharCode(textureID);
const pathsToCreate: InputPath[] = [];
const usesToCreate = uses.map((use, charOffset) => {
// add one to start after the previous letter
const nextLetter = String.fromCharCode(lastCharCode + 1 + charOffset);
// get next letter for each use
const nextLetter = String.fromCharCode(nextCharCode + charOffset);
const newUseID = `${textureID}${nextLetter}`;
// flat paths array to save requests
if (use.paths?.length) pathsToCreate.push(...use.paths.map((p) => ({ ...p, use: newUseID })));
Expand Down

0 comments on commit d979a1c

Please sign in to comment.