Application which will help people create relationships with customers and increase revenue by encouraging customers to visit their business again where they can get more codes and rewards.
Built fully using NextJS and TypeScript. MongoDB is being used as the database.
The basic account entity which stores information about the user themselves. A account belongs to a single Company
, if it's a business account. If it's not a business account, the Company
is unspecified and the user is here only to collect points and scan codes.
If the user decides to create a business account, they will be asked for some basic info about their company. Each user may belong to only one company, and a user can start as many Campaign
s as they wish.
This entire application is based on campaigns. A user can start a campaign which should have a set goal. An example would be a campaign with the name "PlayStation Giveaway" where the user could generate Code
s, which would allow customers to enter the giveaway by scanned said Code
s.
Campaigns can be of many types, and each type should have their own description. This is where we store that info. Some examples of campaign types are: giveaways, points collector and lucky ticket.
Campaign props is where we associate people who scanned codes with what exactly they get by scanning that code. For instance, in the giveaway Campaign Type
, people would get giveaway entries by scanning codes, and this is where we would store how much entries they have, and who exactly has entered the giveaway so far.
These are the actual codes which later get exported as graphical QR Codes for users to scan.
Route | File | Explanation |
---|---|---|
/api/auth/login |
pages/api/auth/login.ts |
Allows for logging in via email and password. POST method must be used. If the login was successful, it will set a cookie which is then used for authentication and authorization. |
/api/auth/register |
pages/api/auth/register.ts |
Allows users to register. Expects RegisterBodyInterface in the body of a POST request. |
/api/auth/me |
pages/api/auth/me.ts |
Expects a GET request and returns a SessionAccount which holds info about the currently logged in user if the user is logged in. Otherwise the isLoggedIn field is false . |
/api/campaigns |
pages/api/campaigns/index.ts |
A GET request will return a list of Campaign s which belong to the currently logged in account, or to be exact, which belong to the accounts Company . A POST request expects a name and a Campaign Type ID, and then creates a Campaign with that info. |
/api/campaigns/{campaignId} |
pages/api/campaigns/[campaignId].ts |
A GET request will return the Campaign that matches the provided campaignId . |
/api/campaigns/scans |
pages/api/campaigns/scans.ts |
Expects a POST request with campaignId in the body. Returns a list of objects which say when a code was scanned and by whom it was scanned. It only shows the first letter of the person who scanned the code. |
/api/campaigns/types |
pages/api/campaigns/types/index.ts |
With a GET request, returns a list of possible Campaign Type s. |
/api/codes/generate |
pages/api/codes/generate.ts |
Expects a POST request with a amount and campaignId parameters in the body. This will generate amount of new active codes for the campaign that matches the campaignId . |
/api/codes/export |
pages/api/codes/export.ts |
Expects a POST request with a campaignId body parameter. Exports all un-scanned codes for that campaign in a .zip format. |
/api/codes/scan/coId/caId/codeId |
pages/api/codes/scan/[...slug].ts |
Expects a GET request with the coId , caId and codeId url parameters and marks the code as scanned. coId must match the company which the code belongs to. caId must match the campaign which the code belongs to. |
/api/codes/me |
pages/api/codes/me.ts |
With a GET request, returns a QR Code SVG in string format that points to the account that generated this code. This is used to redeem rewards in shops. |
/api/account/campaignParticipation/{accountId} |
pages/api/account/campaignParticipation/[accountId].ts |
With a GET request, returns a list of CampaignPropsInterface which basically tells you how much points, entries and etc. each user has in your campaigns. |
/api/account/redeem |
pages/api/account/redeem.ts |
Expects a POST request with campaignPropsId and participantAccountId in the body. Allows you to redeem codes which user scanned, so that they don't try redeeming same reward multiple times. |
/api/account/settings |
pages/api/account/settings.ts |
With a GET request retrieves all account settings which may be changed. With a POST request, changes those settings.
|
/api/company/settings |
pages/api/company/settings.ts |
With a GET request returns an object {qrCodeOptions, logoURL} . With a POST request, changes those settings.
|
/api/company/qr-code-settings |
pages/api/company/qr-code-settings.ts |
With a GET request retrieves all QR code settings which may be changed. With a POST request, changes those settings. With a DELETE request, it resets those options to defaults.
|
/api/dashboard/stats |
pages/api/dashboard/stats.ts |
With a GET request retrieves all kinds of stats which are shown on the dashboard homepage.
|
/api/third-party/cloudinary-signature |
pages/api/third-party/cloudinary-signature.ts |
Expects a GET request and returns object {signature: "", timestamp: ""} which is then used to sign image uploads to Cloudinary. |
These are the environment variables which are needed to get the app running. During development use a .env.local
file, and in production use the Vercel env variable feature.
-
MONGO_URL: URL to the MongoDB database.
-
NODE_ENV:
development
orproduction
. -
AUTH_PASSWORD: The password is a private key you must pass at runtime, it has to be at least 32 characters long. Use 1password.com/password-generator to generate strong passwords.
-
AUTH_COOKIE_NAME: The name of the cookie that stores data about authentication. Should be
AUTH_TOKEN
by default. -
NEXT_PUBLIC_PAGE_DOMAIN: The full domain where the app is currently hosted. For instance
www.google.com
. During production set this tohttp://localhost:3000
. -
AZURE_STORAGE_CONNECTION_STRING: Azure subscription ID for accessing the storage.
-
NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME: Cloudinary Cloud Name where images get uploaded.
-
NEXT_PUBLIC_CLOUDINARY_API_KEY: Cloudinary API Key.
-
CLOUDINARY_API_SECRET: Cloudinary API Secret, must stay private.