Skip to content

Commit

Permalink
Feat change slug to encoding text
Browse files Browse the repository at this point in the history
  • Loading branch information
minai621 committed Jul 30, 2024
1 parent 62f156e commit 7050331
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
15 changes: 7 additions & 8 deletions backend/src/check/check.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Injectable } from "@nestjs/common";
import { JwtService } from "@nestjs/jwt";
import * as moment from "moment";
import { PrismaService } from "src/db/prisma.service";
import { CheckNameConflicReponse } from "./types/check-name-conflict-response.type";
import slugify from "slugify";
import { JwtPayload } from "src/utils/types/jwt.type";
import { CheckYorkieDto, YorkieMethod } from "./dto/check-yorkie.dto";
import { CheckNameConflicReponse } from "./types/check-name-conflict-response.type";
import { CheckYorkieResponse } from "./types/check-yorkie-response.type";
import { JwtService } from "@nestjs/jwt";
import { JwtPayload } from "src/utils/types/jwt.type";
import * as moment from "moment";

@Injectable()
export class CheckService {
Expand All @@ -16,15 +15,15 @@ export class CheckService {
) {}

async checkNameConflict(name: string): Promise<CheckNameConflicReponse> {
const slug = slugify(name, { lower: true });
const encodedText = encodeURIComponent(name);
const conflictUserList = await this.prismaService.user.findMany({
where: {
OR: [{ nickname: name }, { nickname: slug }],
OR: [{ nickname: name }, { nickname: encodedText }],
},
});
const conflictWorkspaceList = await this.prismaService.workspace.findMany({
where: {
OR: [{ title: name }, { title: slug }],
OR: [{ title: name }, { title: encodedText }],
},
});

Expand Down
9 changes: 4 additions & 5 deletions backend/src/users/users.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { ConflictException, Injectable } from "@nestjs/common";
import { User } from "@prisma/client";
import { PrismaService } from "src/db/prisma.service";
import { FindUserResponse } from "./types/find-user-response.type";
import { CheckService } from "src/check/check.service";
import slugify from "slugify";
import { PrismaService } from "src/db/prisma.service";
import { WorkspaceRoleConstants } from "src/utils/constants/auth-role";
import { FindUserResponse } from "./types/find-user-response.type";

@Injectable()
export class UsersService {
Expand Down Expand Up @@ -95,7 +94,7 @@ export class UsersService {
},
});

const slug = slugify(nickname, { lower: true });
const encodedText = encodeURIComponent(nickname);

if (!userWorkspaceList.length) {
const { id: workspaceId } = await this.prismaService.workspace.create({
Expand All @@ -104,7 +103,7 @@ export class UsersService {
},
data: {
title: nickname,
slug,
slug: encodedText,
},
});

Expand Down
11 changes: 5 additions & 6 deletions backend/src/workspaces/workspaces.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import {
UnauthorizedException,
} from "@nestjs/common";
import { Prisma, Workspace } from "@prisma/client";
import * as moment from "moment";
import { CheckService } from "src/check/check.service";
import { PrismaService } from "src/db/prisma.service";
import { FindWorkspacesResponse } from "./types/find-workspaces-response.type";
import { CreateInvitationTokenResponse } from "./types/create-inviation-token-response.type";
import { WorkspaceRoleConstants } from "src/utils/constants/auth-role";
import slugify from "slugify";
import { generateRandomKey } from "src/utils/functions/random-string";
import * as moment from "moment";
import { CheckService } from "src/check/check.service";
import { CreateInvitationTokenResponse } from "./types/create-inviation-token-response.type";
import { FindWorkspacesResponse } from "./types/find-workspaces-response.type";

@Injectable()
export class WorkspacesService {
Expand All @@ -31,7 +30,7 @@ export class WorkspacesService {
const workspace = await this.prismaService.workspace.create({
data: {
title,
slug: slugify(title, { lower: true }),
slug: encodeURIComponent(title),
},
});

Expand Down

0 comments on commit 7050331

Please sign in to comment.