-
Notifications
You must be signed in to change notification settings - Fork 1
/
session.service.ts
31 lines (25 loc) · 889 Bytes
/
session.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { Injectable } from '@nestjs/common';
import { CreateSessionInput } from './inputs/create-session-input';
import { Session } from './session.entity';
import { PrismaService } from '../prisma.service';
@Injectable()
export class SessionService {
constructor(private readonly prisma: PrismaService) {}
async create(createSessionInput: CreateSessionInput): Promise<Session> {
const input = createSessionInput.toSession();
return this.prisma.session.create({
data: {
expires: input.expires,
id: input.id,
token: input.token,
userId: input.userId,
},
});
}
async deleteUserSessions(userId: string): Promise<void> {
await this.prisma.session.deleteMany({ where: { userId } });
}
async findByToken(token: string): Promise<Session | null> {
return this.prisma.session.findUnique({ where: { token } });
}
}