diff --git a/backend/.sqlc/migrations/20241203212121_alter_users_add_email_verified.sql b/backend/.sqlc/migrations/20241203212121_alter_users_add_email_verified.sql new file mode 100644 index 00000000..1eb69165 --- /dev/null +++ b/backend/.sqlc/migrations/20241203212121_alter_users_add_email_verified.sql @@ -0,0 +1,15 @@ +-- +goose Up +-- +goose StatementBegin + +-- by default, goose runs in transactions + +ALTER TABLE users ADD COLUMN email_verified BOOLEAN NOT NULL DEFAULT false; + +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin + +ALTER TABLE users DROP COLUMN email_verified; + +-- +goose StatementEnd diff --git a/backend/.sqlc/queries/users.sql b/backend/.sqlc/queries/users.sql index c22175f9..d7eca9ca 100644 --- a/backend/.sqlc/queries/users.sql +++ b/backend/.sqlc/queries/users.sql @@ -2,11 +2,9 @@ INSERT INTO users ( email, password_hash, - first_name, - last_name, role ) VALUES ( - $1, $2, $3, $4, $5 + $1, $2, $3 ) RETURNING *; -- name: GetUserByEmail :one @@ -15,4 +13,4 @@ WHERE email = $1 LIMIT 1; -- name: GetUserByID :one SELECT * FROM users -WHERE id = $1 LIMIT 1; \ No newline at end of file +WHERE id = $1 LIMIT 1; diff --git a/backend/db/company_questions_answers.sql.go b/backend/db/company_questions_answers.sql.go index 86ec2738..7867fc57 100644 --- a/backend/db/company_questions_answers.sql.go +++ b/backend/db/company_questions_answers.sql.go @@ -65,6 +65,17 @@ func (q *Queries) CreateQuestion(ctx context.Context, questionText string) (Ques return i, err } +const deleteQuestion = `-- name: DeleteQuestion :exec +UPDATE questions +SET deleted_at = NOW() +WHERE id = $1 AND deleted_at IS NULL +` + +func (q *Queries) DeleteQuestion(ctx context.Context, id string) error { + _, err := q.db.Exec(ctx, deleteQuestion, id) + return err +} + const getCompanyAnswer = `-- name: GetCompanyAnswer :one SELECT cqa.id, cqa.company_id, cqa.question_id, cqa.answer_text, cqa.created_at, cqa.updated_at, cqa.deleted_at, diff --git a/backend/db/models.go b/backend/db/models.go index 2f75579a..83d1545e 100644 --- a/backend/db/models.go +++ b/backend/db/models.go @@ -234,4 +234,5 @@ type User struct { CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp Role UserRole + EmailVerified bool } diff --git a/backend/db/users.sql.go b/backend/db/users.sql.go index de3ab9df..cffd59f4 100644 --- a/backend/db/users.sql.go +++ b/backend/db/users.sql.go @@ -13,30 +13,20 @@ const createUser = `-- name: CreateUser :one INSERT INTO users ( email, password_hash, - first_name, - last_name, role ) VALUES ( - $1, $2, $3, $4, $5 -) RETURNING id, email, password_hash, first_name, last_name, wallet_address, created_at, updated_at, role + $1, $2, $3 +) RETURNING id, email, password_hash, first_name, last_name, wallet_address, created_at, updated_at, role, email_verified ` type CreateUserParams struct { Email string PasswordHash string - FirstName *string - LastName *string Role UserRole } func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) { - row := q.db.QueryRow(ctx, createUser, - arg.Email, - arg.PasswordHash, - arg.FirstName, - arg.LastName, - arg.Role, - ) + row := q.db.QueryRow(ctx, createUser, arg.Email, arg.PasswordHash, arg.Role) var i User err := row.Scan( &i.ID, @@ -48,12 +38,13 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e &i.CreatedAt, &i.UpdatedAt, &i.Role, + &i.EmailVerified, ) return i, err } const getUserByEmail = `-- name: GetUserByEmail :one -SELECT id, email, password_hash, first_name, last_name, wallet_address, created_at, updated_at, role FROM users +SELECT id, email, password_hash, first_name, last_name, wallet_address, created_at, updated_at, role, email_verified FROM users WHERE email = $1 LIMIT 1 ` @@ -70,12 +61,13 @@ func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error &i.CreatedAt, &i.UpdatedAt, &i.Role, + &i.EmailVerified, ) return i, err } const getUserByID = `-- name: GetUserByID :one -SELECT id, email, password_hash, first_name, last_name, wallet_address, created_at, updated_at, role FROM users +SELECT id, email, password_hash, first_name, last_name, wallet_address, created_at, updated_at, role, email_verified FROM users WHERE id = $1 LIMIT 1 ` @@ -92,6 +84,7 @@ func (q *Queries) GetUserByID(ctx context.Context, id string) (User, error) { &i.CreatedAt, &i.UpdatedAt, &i.Role, + &i.EmailVerified, ) return i, err }