Q:

Function parameter - id vs object

I have some service that return user's data by it's id.
User already stored in request(session) - no need to fetch it every time.
The question is what is the best practice for parameter. Id of the user(SOLID) or user object(more validation/typings).
Example:
//...

// this
public async getByUser(user: User) {
  return await Transaction.findAll({
    where: { userId: user.id }
  });
}

// or this
public async getByUser(userId: number) {
  return await Transaction.findAll({
    where: { userId }
  });
}

A:

Either. Really.
Just keep the naming proper.
The more declarative your function names, the less confusion
//...

// this
public async getByUser(user: User) {
  return await Transaction.findAll({
    where: { userId: user.id }
  });
}

// or this
public async getByUserId(userId: number) {
  return await Transaction.findAll({
    where: { userId }
  });
}

