Skip to content

Commit

Permalink
feat: (hard) delete user
Browse files Browse the repository at this point in the history
  • Loading branch information
seohyun-kim committed Jan 22, 2022
1 parent 831e63e commit 1f5060f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/infrastructure/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ormconfig from '../ormconfig';

export async function startTypeORM() {
const connection = await createConnection(ormconfig);
await connection.synchronize(true);
//await connection.synchronize(true);

console.log('db 연결 성공');
}
9 changes: 8 additions & 1 deletion src/server/libs/application/user/user-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ class UserRepository extends Repository<User> {
const user = await User.createQueryBuilder().insert().into(User).values({ email,nickname,oauthProvider,oauthId}).execute();
return user.identifiers[0].id;
}


async deleteUser(oauthId:string): Promise<string> {
const user = await User.createQueryBuilder().
delete().from(User).
where("oauthId = :oauthId", {oauthId:oauthId}).execute();

return ;
}

}

Expand Down
20 changes: 20 additions & 0 deletions src/server/routes/users/deleteUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {defineSchema} from '../../libs/schema';
import {z} from 'zod';
import {defineRoute} from '../../libs/route';
import {getCustomRepository} from "typeorm";
import UserRepository from "../../libs/application/user/user-repository";


const schema = defineSchema({
params: {
oauthId: z.string(),
},
});

export default defineRoute('delete', '/user/:oauthId?', schema, async (req, res) => {

const {oauthId} = req.params;
await getCustomRepository(UserRepository).deleteUser(oauthId);

res.send();
});

0 comments on commit 1f5060f

Please sign in to comment.