89 lines
2.8 KiB
TypeScript
89 lines
2.8 KiB
TypeScript
import {
|
|
Args, Mutation, Query, Resolver,
|
|
} from '@nestjs/graphql';
|
|
import * as GraphQLUpload from 'graphql-upload/GraphQLUpload.js';
|
|
import * as Upload from 'graphql-upload/Upload.js';
|
|
|
|
import { User } from '@/prisma/generated';
|
|
import { UserModel } from '@/src/module/auth/account/models/user.model';
|
|
import { ChangeProfileInfoInput } from '@/src/module/auth/profile/inputs/change-profile-info.input';
|
|
import {
|
|
SocialLinkInput,
|
|
SocialLinkOrderInput,
|
|
} from '@/src/module/auth/profile/inputs/social-link.input';
|
|
import { Authorization } from '@/src/shared/decorators/auth.decorator';
|
|
import { Authorized } from '@/src/shared/decorators/authorized.decorator';
|
|
import { FileValidationPipe } from '@/src/shared/pipes/file-validation.pipe';
|
|
|
|
import { SocialLinkModel } from './models/social-link.model';
|
|
import { ProfileService } from './profile.service';
|
|
|
|
@Resolver('Profile')
|
|
export class ProfileResolver {
|
|
constructor(private readonly profileService: ProfileService) {}
|
|
|
|
@Authorization()
|
|
@Mutation(() => Boolean, { name: 'changeProfileAvatar' })
|
|
public async changeAvatar(
|
|
@Authorized() user: User,
|
|
@Args('avatar', { type: () => GraphQLUpload }, FileValidationPipe) file: Upload,
|
|
) {
|
|
return this.profileService.changeAvatar(user, file);
|
|
}
|
|
|
|
@Authorization()
|
|
@Mutation(() => Boolean, { name: 'removeProfileAvatar' })
|
|
public async removeAvatar(@Authorized() user: User) {
|
|
return this.profileService.removeAvatar(user);
|
|
}
|
|
|
|
@Authorization()
|
|
@Mutation(() => UserModel, { name: 'changeProfileInfo' })
|
|
public async changeInfo(
|
|
@Authorized() user: User,
|
|
@Args('data') input: ChangeProfileInfoInput,
|
|
) {
|
|
return this.profileService.changeInfo(user, input);
|
|
}
|
|
|
|
@Authorization()
|
|
@Mutation(() => SocialLinkModel, { name: 'createSocialLink' })
|
|
public async createSocialLink(
|
|
@Authorized() user: User,
|
|
@Args('data') input: SocialLinkInput,
|
|
) {
|
|
return this.profileService.createSocialLink(user, input);
|
|
}
|
|
|
|
@Authorization()
|
|
@Mutation(() => Boolean, { name: 'reorderSocialLink' })
|
|
public async reorderSocialLinks(
|
|
@Args('list', { type: () => [SocialLinkOrderInput] }) list: SocialLinkOrderInput[],
|
|
) {
|
|
return this.profileService.reorderSocialLinks(list);
|
|
}
|
|
|
|
@Authorization()
|
|
@Mutation(() => SocialLinkModel, { name: 'updateSocialLink' })
|
|
public async updateSocialLink(
|
|
@Args('id') id: string,
|
|
@Args('data') input: SocialLinkInput,
|
|
) {
|
|
return this.profileService.updateSocialLink(id, input);
|
|
}
|
|
|
|
@Authorization()
|
|
@Mutation(() => Boolean, { name: 'removeSocialLink' })
|
|
public async removeSocialLink(
|
|
@Args('id') id: string,
|
|
) {
|
|
return this.profileService.removeSocialLink(id);
|
|
}
|
|
|
|
@Authorization()
|
|
@Query(() => [SocialLinkModel], { name: 'findSocialLinks' })
|
|
public async findSocialLink(@Authorized() user: User) {
|
|
return this.profileService.findSocialLink(user);
|
|
}
|
|
}
|