Skip to content
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

Fix TypeScript example to use actually supported types #756

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions docs/business-logic/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,28 @@ You can do this by adding the following code to the `functions.ts` file:
import { Client } from "pg";
import bcrypt from "bcrypt";

// Define the User type using TypeScript
type User = {
// Define a type to capture a new user's details using TypeScript
type NewUser = {
name: string;
email: string;
password: string; // Add a password field to the User type
};

// Define a type to capture the created User
type User = {
id: number;
name: string;
email: string;
};

/**
* Inserts a user into the database and returns the inserted user.
* Hash password for secure storage.
*
* @param user The user to insert into the database. Expects a name, email, and password.
* @returns The user that was inserted into the database.
*/
export async function insertUser(user: User): Promise<Omit<User, "password">> {
export async function insertUser(user: NewUser): Promise<User> {
// Get your database connection string.
// NB!! Use env vars for this in production NB!!
const connectionString = "postgresql://username:password@localhost:5432/mydb";
Expand Down
Loading