-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: seed with service #75
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I really like the direction we are going!
await usersService.createUser({ | ||
email: faker.internet.email(), | ||
username: faker.internet.userName(), | ||
password: await Bun.password.hash(faker.internet.password()), | ||
bio: faker.lorem.text(), | ||
image: faker.image.imageUrl(), | ||
}; | ||
console.log('Upserting user:', data); | ||
password: faker.internet.password(), | ||
}); | ||
|
||
await db.insert(users).values(data); | ||
console.log('User upserted'); | ||
// Update the user's bio and image | ||
await usersService.updateUser(i, { | ||
bio: faker.lorem.paragraph(), | ||
image: faker.internet.avatar(), | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be able to create a user with all attributes. It's just that the frontend won't send the two optional keys in the registration request
async findAll() { | ||
const users = await this.repository.findAll(); | ||
return await Promise.all( | ||
users.map((user) => this.generateUserResponse(user)), | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see two problems with this:
- It'll generate a valid token for ALL users, which is probably not a good thing to do regardless if it's exposed in an API or not
- Although the spec doesn't talk about a functionality like this, but I think the returned data format should be changed. Instead of a list of singular user objects (
{user: {...}}[]
) it could be one plural users object, e.g.{users: [user1, user2]}
Description
This PR suggests treating the seeder as a service controller rather than as a direct database manipulator.
Having the seeding device interact with the service layer achieves 2 goals:
PR Checklist (Please do not remove)
type(scope): description
ortype: description
formatReference an issue or discussion where the feature or changes have been previously discussedAdd a failing test that passes with the changes introduced in this PR, or explain why it's not feasibleAdd documentation for the feature or changes introduced in this PR to the docs; you can run them withbun docs