I am trying to make a simple reddit clone. I have a Space enitity which is like a community in actual Reddit.
@ObjectType()
@Entity()
export class Spaces extends BaseEntity {
@Field()
@PrimaryGeneratedColumn("uuid")
spaceId: string;
@Field()
@Column("text")
adminId: string;
@Field()
@Column("text", { default: "public" })
type: string;
@Field()
@Column("text", { unique: true })
spaceName!: string;
@Field()
@OneToMany(() => Post, (post) => post.space)
posts: Post;
@Field()
@Column("text", { array: true , default:[]} )
bannedUserIds: string[];
@ManyToMany(() => User , (user) => user.spaces , {
cascade: true
})
@JoinTable()
users: User[]
}
And this is my User Entity
@ObjectType()
@Entity()
export class User extends BaseEntity {
@Field(() => ID)
@PrimaryGeneratedColumn("uuid")
id!: string;
@Field()
@Column("text" , {unique: true})
studentId!: string;
@Field()
@Column("text")
name!: string;
@Field()
@Column("text", { unique: true })
username!: string;
@Field()
@Column("text", { unique: true })
email!: string;
@Field()
@Column("text")
gender!: string;
@Field()
@Column("bool", { default: false })
godAdmin!: boolean;
@Field()
@Column("bool", { default: true })
isConfirmed!: boolean;
@Field()
@Column("text")
password!: string;
@Field()
@Column({
type: "text",
default:
"https://image.shutterstock.com/image-vector/blank-avatar-placeholder-on-transparent-600w-1097191784.jpg",
})
avatarUrl!: string;
@Field()
@Column("bool", { default: false })
isBanned: boolean;
@Field()
@Column("int", { default: 0 })
striked: number;
@Field()
@Column({ type: "text", nullable: true, default: "" })
bio: string;
@Field()
@Column({ type: "text", nullable: true, default: "" })
instagramAcc!: string;
@Field()
@Column({ type: "text", nullable: true, default: "" })
twitterAcc!: string;
@Field()
@Column({ type: "text", nullable: true, default: "" })
GithubAcc!: string;
@OneToMany(() => Updoot, (updoot) => updoot.user)
updoots: Updoot[];
@Field()
@OneToMany(() => Post, (post) => post.creator)
posts: Post[];
@ManyToMany(() => Spaces , (space) => space.users )
spaces: Spaces[]
}
I am also using type-graphql to make my APIs. I have a createSpace mutation
@Mutation(() => Boolean)
@UseMiddleware(isAuth)
async createSpace(
@Arg("spaceName") spaceName: string,
@Ctx() { req }: MyContext
): Promise<boolean> {
const user = await User.findOne({id: req.session.userId});
await Spaces.create({
spaceName: spaceName,
adminId: req.session.userId,
users: [user]
}).save();
return true;
}
But this is giving me an error "No Overload Matches This Call". I want to add Admin of this space when this space is created. Can anyone help me to solve this issue?
