Welcome to the Inkspiff Demo API Repository! This project is a TypeScript-based backend service designed to handle contact-related operations efficiently. It utilizes Prisma as an ORM for seamless database interactions and follows the MVC architecture principles for a clean separation of concerns.
- Identify contacts by email or phone number.
- Retrieve all contacts based on search criteria.
- Clear all contacts securely with password protection.
- TypeScript: For type safety and modern JavaScript features.
- Node.js: As the runtime environment.
- Express: For building the RESTful API.
- Prisma: As the ORM for database interactions.
To get started with this project, follow these steps:
-
Clone the repository:
git clone https://github.com/Inkspiff/inkspiff-demo-api-repo.git cd inkspiff-demo-api-repo
-
Install dependencies:
npm install
-
Set up your environment variables: Create a
.env
file in the root directory and add your database connection string:DATABASE_URL=your_database_url CLEAR_PASSWORD=your_secure_password
-
Run the application:
npm start
The server will start on
http://localhost:3000
.
- POST
/identify
- Request Body:
{ "email": "string", "phoneNumber": "string" }
- Description: Identifies a contact based on email or phone number.
- Request Body:
- GET
/identify
- Query Parameters:
email
,phoneNumber
- Description: Retrieves all contacts matching the criteria.
- Query Parameters:
- DELETE
/identify
- Query Parameters:
email
,phoneNumber
,password
- Description: Clears all contacts matching the criteria if the correct password is provided.
- Query Parameters:
The project is organized into the following directories:
- controllers/: Contains the logic for handling requests and responses.
- services/: Contains business logic and interactions with the database.
- routes/: Defines the API endpoints and their corresponding controllers.
- config/: Configuration files, including Prisma setup.
- prisma/: Contains the Prisma schema for database modeling.
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
export default prisma;
export const identify = async (req: any, res: any) => {
try {
const { email, phoneNumber } = req.body;
const result = await identifyContact(email || null, phoneNumber || null);
res.json({ contact: result });
} catch (error: any) {
return res.status(400).json({ error: error.message });
}
};
model Contact {
id Int @id @default(autoincrement())
phoneNumber String?
email String?
linkedId Int?
linkPrecedence LinkPrecedence @default(primary)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
}
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to explore the code and contribute to the project!