Skip to content

Instantly share code, notes, and snippets.

@danphilibin
Created August 7, 2023 16:56
Show Gist options
  • Save danphilibin/124f3ec9987fb25a1f751895e1e4e275 to your computer and use it in GitHub Desktop.
Save danphilibin/124f3ec9987fb25a1f751895e1e4e275 to your computer and use it in GitHub Desktop.
Chat transcript from demo of using Aider (https://aider.chat) and Interval (https://interval.com) to build internal tools.

Aider v0.8.3
/Users/dan/.pyenv/versions/3.10.9/bin/aider DOCS.md src/index.ts src/utils/db.ts src/utils/stripe.ts prisma/schema.prisma
Model: gpt-4
Git repo: .git
Repo-map: universal-ctags using 1024 tokens
Added DOCS.md to the chat.
Added prisma/schema.prisma to the chat.
Added src/index.ts to the chat.
Added src/utils/db.ts to the chat.
Added src/utils/stripe.ts to the chat.
Use /help to see in-chat commands, run with --help to see cmd line args

write a createUser action that asks for name and email address and creates the user in the database

To create a createUser action, we need to create a new file in the src/routes directory. Let's call it createUser.ts. This file will contain the action that asks for the user's name and email address and creates the user in the database.

Here are the steps:

  1. Create a new file src/routes/createUser.ts.
  2. Import the necessary modules and functions.
  3. Define the action that asks for the user's name and email.
  4. Use the prisma client to create a new user in the database.

Here is the code:

src/routes/createUser.ts
<<<<<<< ORIGINAL

=======
import { Action, io } from "@interval/sdk";
import prisma from "../utils/db";

export default new Action({
  name: "Create User",
  description: "Create a new user",
  handler: async () => {
    const { name, email } = await io.group({
      name: io.input.text("Name"),
      email: io.input.email("Email"),
    });

    await prisma.user.create({
      data: {
        name,
        email,
      },
    });

    await io.display.markdown("User created successfully");
  },
});
>>>>>>> UPDATED

This code creates a new action that asks for the user's name and email address, creates a new user in the database using the prisma client, and then displays a success message.

Allow creation of new file src/routes/createUser.ts? y
Add src/routes/createUser.ts to git? y
Applied edit to src/routes/createUser.ts
Commit 38d7200 aider: Created a createUser action that asks for name and email address and creates the user in the database.

add validation to the email field in createUser and make sure the email doesn't already exist in the database

To add validation to the email field in the createUser action, we need to modify the src/routes/createUser.ts file. We will add a validation function to the email input that checks if the email already exists in the database.

Here are the steps:

  1. Modify the src/routes/createUser.ts file.
  2. Add a validation function to the email input that checks if the email already exists in the database.

Here is the code:

src/routes/createUser.ts
<<<<<<< ORIGINAL
import { Action, io } from "@interval/sdk";
import prisma from "../utils/db";

export default new Action({
  name: "Create User",
  description: "Create a new user",
  handler: async () => {
    const { name, email } = await io.group({
      name: io.input.text("Name"),
      email: io.input.email("Email"),
    });

    await prisma.user.create({
      data: {
        name,
        email,
      },
    });

    await io.display.markdown("User created successfully");
  },
});
=======
import { Action, io } from "@interval/sdk";
import prisma from "../utils/db";

export default new Action({
  name: "Create User",
  description: "Create a new user",
  handler: async () => {
    const { name, email } = await io.group({
      name: io.input.text("Name"),
      email: io.input.email("Email").validate(async (email) => {
        const existingUser = await prisma.user.findUnique({
          where: { email },
        });
        if (existingUser) {
          return "This email is already in use.";
        }
      }),
    });

    await prisma.user.create({
      data: {
        name,
        email,
      },
    });

    await io.display.markdown("User created successfully");
  },
});
>>>>>>> UPDATED

This code adds a validation function to the email input that checks if the email already exists in the database. If the email already exists, it returns an error message.

Applied edit to src/routes/createUser.ts
Commit 76ccda8 aider: Add validation to the email field in createUser and ensure the email doesn't already exist in the database.

create an action that lists my most recent stripe transactions. format the dollar amounts as US currency.

To create an action that lists your most recent Stripe transactions, we need to create a new file in the src/routes directory. Let's call it listTransactions.ts. This file will contain the action that fetches the transactions from Stripe and formats the dollar amounts as US currency.

Here are the steps:

  1. Create a new file src/routes/listTransactions.ts.
  2. Import the necessary modules and functions.
  3. Define the action that fetches the transactions from Stripe and formats the dollar amounts as US currency.

Here is the code:

src/routes/listTransactions.ts
<<<<<<< ORIGINAL

=======
import { Action, io } from "@interval/sdk";
import stripe from "../utils/stripe";

export default new Action({
  name: "List Transactions",
  description: "List the most recent Stripe transactions",
  handler: async () => {
    const transactions = await stripe.charges.list({ limit: 10 });

    const formattedTransactions = transactions.data.map((transaction) => ({
      id: transaction.id,
      amount: new Intl.NumberFormat("en-US", {
        style: "currency",
        currency: "USD",
      }).format(transaction.amount / 100),
      date: new Date(transaction.created * 1000).toLocaleDateString(),
    }));

    await io.display.table("Recent Transactions", {
      data: formattedTransactions,
      columns: ["id", "amount", "date"],
    });
  },
});
>>>>>>> UPDATED

This code creates a new action that fetches the most recent transactions from Stripe, formats the dollar amounts as US currency, and then displays the transactions in a table.

Allow creation of new file src/routes/listTransactions.ts? y
Add src/routes/listTransactions.ts to git? y
Applied edit to src/routes/listTransactions.ts
Commit 5f2cccb aider: Created an action that lists the most recent Stripe transactions and formats the dollar amounts as US currency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment