|
|
@@ -20,13 +20,18 @@ impl Home {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- pub async fn insert(&self, db: &PgPool) -> Result<(), AppError> {
|
|
|
+ pub async fn insert(&self, db: &PgPool, user_id: Uuid) -> Result<(), AppError> {
|
|
|
sqlx::query!(
|
|
|
- "INSERT INTO homes (id, name, created_at)
|
|
|
- VALUES($1, $2, $3)",
|
|
|
+ "WITH _ AS (
|
|
|
+ INSERT INTO homes (id, name, created_at)
|
|
|
+ VALUES ($1, $2, $3)
|
|
|
+ )
|
|
|
+ INSERT INTO users_homes (user_id, home_id, is_admin)
|
|
|
+ VALUES ($4, $1, true)",
|
|
|
self.id,
|
|
|
self.name,
|
|
|
- self.created_at
|
|
|
+ self.created_at,
|
|
|
+ user_id
|
|
|
)
|
|
|
.execute(db)
|
|
|
.await?;
|