# User logic

First, let's inject a <mark style="color:blue;">`PrismaService`</mark> in the <mark style="color:blue;">`UsersService`</mark>, which will give us an interface for interacting with the database, much like TypeORM's <mark style="color:blue;">`Repository`</mark>.

```typescript
private readonly prisma: PrismaService
```

Now, we shall implement each one of the methods. Note that the interface offered by Prisma is very intuitive and succint. Instead of needing a <mark style="color:blue;">`repository`</mark> for each entity, <mark style="color:blue;">`prisma`</mark> simply accesses the desired entity and then the operation.

```typescript
create(createUserDto: CreateUserDto) {
  return this.prisma.user.create({ data: createUserDto });
}

findAll() {
  return this.prisma.user.findMany();
}

findOne(id: number) {
  return this.prisma.user.findUniqueOrThrow({ where: { id } });
}

update(id: number, updateUserDto: UpdateUserDto) {
  return this.prisma.user.update({ where: { id }, data: updateUserDto });
}

remove(id: number) {
  return this.prisma.user.delete({ where: { id } });
}
```

{% hint style="info" %}
A huge advantage that Prisma has in comparison to TypeORM is the type safety offered when fetching entities. For instance, if an entity is fetched without a certain relation, then a dynamic type is generated to prevent it from being accessible.
{% endhint %}

<mark style="color:green;">**Commit**</mark> - Implementing user logic
