Skip to content

Commit

Permalink
fix: resource ref creation
Browse files Browse the repository at this point in the history
  • Loading branch information
drodil committed Feb 12, 2025
1 parent 40cb5b5 commit f10661a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
8 changes: 6 additions & 2 deletions plugins/qeta-backend/src/database/QetaStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ import { QetaFilters } from '../service/util';
import { PermissionCriteria } from '@backstage/plugin-permission-common';

export function isPost(entity: Post | Answer | Comment): entity is Post {
return 'answers' in entity;
return 'title' in entity;
}

export function isAnswer(entity: Post | Answer | Comment): entity is Answer {
return !('answers' in entity);
return 'postId' in entity && 'correct' in entity;
}

export function isComment(entity: Post | Answer | Comment): entity is Comment {
return !('title' in entity) && !('correct' in entity);
}

export type MaybeAnswer = Answer | null;
Expand Down
14 changes: 2 additions & 12 deletions plugins/qeta-backend/src/service/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import {
PolicyDecision,
} from '@backstage/plugin-permission-common';
import {
isAnswer,
isComment,
isPost,
MaybeAnswer,
MaybeComment,
MaybePost,
} from '../database/QetaStore';
import { Config } from '@backstage/config';
Expand Down Expand Up @@ -48,17 +49,6 @@ import { BlobServiceClient } from '@azure/storage-blob';
import { DefaultAzureCredential } from '@azure/identity';
import { BackstagePrincipalTypes } from '@backstage/backend-plugin-api';

export const isAnswer = (
ent: MaybePost | MaybeAnswer | MaybeComment,
): ent is Answer => ent !== null && (ent as Answer).postId !== undefined;

export const isComment = (
ent: MaybePost | MaybeAnswer | MaybeComment,
): ent is Comment =>
ent !== null &&
(ent as Answer).postId === undefined &&
(ent as Post).title === undefined;

export const getUsername = async (
req: Request<unknown>,
options: RouterOptions,
Expand Down

0 comments on commit f10661a

Please sign in to comment.