Skip to content

Commit

Permalink
add class name to services
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnmclean committed Dec 18, 2024
1 parent 6fd7116 commit f6775d1
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/sovoli.com/src/services/baseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const tracer = trace.getTracer("sovoli-services");

export abstract class BaseService<TOptions, TResult = void> {
constructor(
protected readonly name: string,
protected readonly dbClient: typeof db = db,
protected readonly logger: Logger = new Logger(),
protected readonly name: string = new.target.name,
) {}

protected abstract execute(options: TOptions): Promise<TResult>;
Expand Down
4 changes: 4 additions & 0 deletions apps/sovoli.com/src/services/books/findBookByISBN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export class FindBookByISBN extends BaseService<
FindBookByISBNOptions,
FindBookByISBNResult
> {
constructor() {
super("FindBookByISBN");
}

protected async execute({ isbn, forceExternal }: FindBookByISBNOptions) {
const internalBook = await db.query.Book.findFirst({
where: or(eq(schema.Book.isbn10, isbn), eq(schema.Book.isbn13, isbn)),
Expand Down
3 changes: 3 additions & 0 deletions apps/sovoli.com/src/services/import/createShelfImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export class CreateShelfImport extends BaseService<
CreateShelfImportOptions,
CreateShelfImportResult
> {
constructor() {
super("CreateShelfImport");
}
async execute({ authUserId, mapping, csvContent }: CreateShelfImportOptions) {
// authorization check for existing shelves
const existingShelfIds =
Expand Down
3 changes: 3 additions & 0 deletions apps/sovoli.com/src/services/isbndb/getBookFromISBNdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export class GetBookFromISBNdb extends BaseService<
GetBookFromISBNdbOptions,
GetBookFromISBNdbResult
> {
constructor() {
super("GetBookFromISBNdb");
}
protected async execute({ isbn }: GetBookFromISBNdbOptions) {
const apiKey = env.ISBN_DB_API_KEY;
const url = `https://api2.isbndb.com/book/${isbn}`;
Expand Down
4 changes: 4 additions & 0 deletions apps/sovoli.com/src/services/knowledge/getKnowledges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export class GetKnowledges extends BaseService<
GetKnowledgesOptions,
GetKnowledgesResult
> {
constructor() {
super("GetKnowledges");
}

protected async execute({
authUserId,
username,
Expand Down
3 changes: 3 additions & 0 deletions apps/sovoli.com/src/services/knowledge/publishKnowledge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export interface PublishKnowledgeOptions {
}

export class PublishKnowledge extends BaseService<PublishKnowledgeOptions> {
constructor() {
super("PublishKnowledge");
}
async execute({ authUserId, knowledgeId }: PublishKnowledgeOptions) {
const knowledge = await this.dbClient.query.Knowledge.findFirst({
where: eq(schema.Knowledge.id, knowledgeId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export class GetUserProfileByUsername extends BaseService<
GetUserProfileByUsernameOptions,
UserProfile | null
> {
constructor() {
super("GetUserProfileByUsername");
}

async execute({ username }: GetUserProfileByUsernameOptions) {
const user = await this.dbClient.query.User.findFirst({
where: eq(schema.User.username, username),
Expand Down

0 comments on commit f6775d1

Please sign in to comment.