diff --git a/packages/api/src/entity/label.ts b/packages/api/src/entity/label.ts index dec2046f4..0b36eddec 100644 --- a/packages/api/src/entity/label.ts +++ b/packages/api/src/entity/label.ts @@ -4,13 +4,10 @@ import { CreateDateColumn, Entity, JoinColumn, - JoinTable, - ManyToMany, ManyToOne, PrimaryGeneratedColumn, } from 'typeorm' import { User } from './user' -import { Link } from './link' @Entity({ name: 'labels' }) export class Label extends BaseEntity { @@ -24,10 +21,6 @@ export class Label extends BaseEntity { @JoinColumn({ name: 'user_id' }) user!: User - @ManyToMany(() => Link, (link) => link.labels) - @JoinTable({ name: 'link_labels' }) - link?: Link - @Column('text') color!: string diff --git a/packages/api/src/entity/link.ts b/packages/api/src/entity/link.ts index fcd9ee2f4..40c0f208a 100644 --- a/packages/api/src/entity/link.ts +++ b/packages/api/src/entity/link.ts @@ -63,7 +63,11 @@ export class Link extends BaseEntity { @UpdateDateColumn() updatedAt?: Date - @ManyToMany(() => Label, (label) => label.link) - @JoinTable({ name: 'link_labels' }) + @ManyToMany(() => Label) + @JoinTable({ + name: 'link_labels', + joinColumn: { name: 'link_id' }, + inverseJoinColumn: { name: 'label_id' }, + }) labels?: Label[] } diff --git a/packages/api/src/entity/link_label.ts b/packages/api/src/entity/link_label.ts new file mode 100644 index 000000000..5bcdd64d6 --- /dev/null +++ b/packages/api/src/entity/link_label.ts @@ -0,0 +1,27 @@ +import { + BaseEntity, + CreateDateColumn, + Entity, + JoinColumn, + ManyToOne, + PrimaryGeneratedColumn, +} from 'typeorm' +import { Link } from './link' +import { Label } from './label' + +@Entity({ name: 'link_labels' }) +export class LinkLabel extends BaseEntity { + @PrimaryGeneratedColumn('uuid') + id!: string + + @ManyToOne(() => Link) + @JoinColumn({ name: 'link_id' }) + link!: Link + + @ManyToOne(() => Label) + @JoinColumn({ name: 'label_id' }) + label!: Label + + @CreateDateColumn() + createdAt!: Date +} diff --git a/packages/api/src/generated/graphql.ts b/packages/api/src/generated/graphql.ts index e854ff299..c844284eb 100644 --- a/packages/api/src/generated/graphql.ts +++ b/packages/api/src/generated/graphql.ts @@ -778,6 +778,7 @@ export type Mutation = { setBookmarkArticle: SetBookmarkArticleResult; setDeviceToken: SetDeviceTokenResult; setFollow: SetFollowResult; + setLabels: SetLabelsResult; setLinkArchived: ArchiveLinkResult; setShareArticle: SetShareArticleResult; setShareHighlight: SetShareHighlightResult; @@ -919,6 +920,11 @@ export type MutationSetFollowArgs = { }; +export type MutationSetLabelsArgs = { + input: SetLabelsInput; +}; + + export type MutationSetLinkArchivedArgs = { input: ArchiveLinkInput; }; @@ -1350,6 +1356,29 @@ export type SetFollowSuccess = { updatedUser: User; }; +export type SetLabelsError = { + __typename?: 'SetLabelsError'; + errorCodes: Array; +}; + +export enum SetLabelsErrorCode { + BadRequest = 'BAD_REQUEST', + NotFound = 'NOT_FOUND', + Unauthorized = 'UNAUTHORIZED' +} + +export type SetLabelsInput = { + labelIds: Array; + linkId: Scalars['ID']; +}; + +export type SetLabelsResult = SetLabelsError | SetLabelsSuccess; + +export type SetLabelsSuccess = { + __typename?: 'SetLabelsSuccess'; + labels: Array