Menu

What my register endpoint does before it saves anyone: transactions, soft deletes, and a poka-yoke in NestJS
📰

What my register endpoint does before it saves anyone: transactions, soft deletes, and a poka-yoke in NestJS

DEV Community: nestjs·Ziad Taha·6 days ago
#aHlPTbJB
#devtonestjs#devto#dev#password#role
Long article (1084 words) — no AI summary yet.
Reading 0:00
15s threshold

I'm a junior full-stack developer from Alexandria, Egypt. This is another post about FaceMark, my face-recognition attendance system (a NestJS API plus a Python AI service), and this time it's about the auth service: what actually happens when someone registers or logs in.

The save is the last thing that happens

Registering is a transaction, not a save call

My register method doesn't call save() on a new user right away. It opens a transaction first, because two weird cases live inside it:

async register ( registerDto : RegisterDto ) { const { username , password , role } = registerDto ;

return await this . dataSource . transaction ( async ( manager ) => { const transactionalRepo = manager . getRepository ( UserAccount ) ;

const existingUser = await transactionalRepo . findOne ( { where : { username } , } ) ;

if ( existingUser ) { if ( ! existingUser .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.