9 Commits

Author SHA1 Message Date
Aarish
f86bfee3f3 Updat name - getByDomainName() returns an array 2025-05-25 17:14:26 -05:00
Aarish
57c393d939 Add a method to fetch by domain 2025-05-25 17:11:34 -05:00
Aarish
f28328dcc4 Remove name from insert method - this is removed from db schema 2025-05-25 17:06:37 -05:00
Aarish
b9967a8e66 handle errors thrown by model incase there is any error while fetching the site 2025-05-25 16:58:34 -05:00
Aarish
512d18ec23 update index.js to show domain_name 2025-05-24 21:09:27 -05:00
Aarish
c364e31ee3 handle exceptions while adding the site 2025-05-24 18:37:54 -05:00
Aarish
061f9121b9 add insert validation 2025-05-24 18:37:36 -05:00
Aarish
1ef5815f65 domain name validation logic 2025-05-24 18:36:56 -05:00
Aarish
f9710d4387 Fix insert request 2025-05-24 18:16:45 -05:00
7 changed files with 96 additions and 79 deletions

View File

@@ -1,26 +0,0 @@
name: Sync TODOs with Issues
on:
workflow_dispatch:
push:
paths-ignore:
- '**.md'
jobs:
sync_todos:
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Sync TODOs
uses: Solo-Web-Works/TODO-Sync@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
summary_file: TODO_SUMMARY.md
dry_run: false
commit: false

View File

@@ -13,4 +13,4 @@ $env:DEBUG='playwright-a11y-dashboard:*'; npm start
## Notes, issues, and tasks
- [Initial Project Outline](Outline.md)
- [Project Task Board](https://git.keithsolomon.net/keith/Playwright-A11y-Dashboard/projects/2)
- [Project Task Board](https://git.keithsolomon.net/keith/Playwright-A11y-Dashboard/projects/1)

13
helpers/utils.js Normal file
View File

@@ -0,0 +1,13 @@
/**
* Utility functions for the application.
*/
const isValidDomain = (domain) => {
// Regular expression to validate a domain name
const domainRegex = /^(?!:\/\/)([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/;
return domainRegex.test(domain);
}
module.exports = {
isValidDomain
};

View File

@@ -3,6 +3,7 @@
*/
const { supabase } = require('../auth');
const { isValidDomain } = require('../helpers/utils');
class SiteModel {
@@ -16,11 +17,25 @@ class SiteModel {
*
* @returns {Promise<Object>} - The result of the insert operation.
*/
async insert(name, domainName) {
const { error } = await supabase.from(siteModel.tableName).insert({
name: name,
async insert(domainName) {
// validate inputs
if (!domainName) {
throw new Error('Name and domain name are required to insert a site.');
}
// validate domain name format
if (!isValidDomain(domainName)) {
throw new Error('Invalid domain name format.');
}
// check if the domain name already exists
if (await this.getByDomainName(domainName).then(data => data.length !== 0)) {
throw new Error('Domain name already exists.');
}
const { data, error } = await supabase.from(SiteModel.tableName).insert({
domain_name: domainName,
});
}).select();
if (error) {
console.error('Error inserting site:', error);
@@ -64,6 +79,24 @@ class SiteModel {
return data;
}
/**
* Retrieves a site by its domain name.
*
* @param {string} domainName - The domain name of the site.
*
* @returns {Promise<Object>} - The site object.
*/
async getByDomainName(domainName) {
const { data, error } = await supabase.from(SiteModel.tableName).select('*').eq('domain_name', domainName);
if (error) {
console.error('Error fetching site by domain name:', error);
throw error;
}
return data;
}
}
module.exports = SiteModel;

View File

@@ -19,8 +19,6 @@
--text-base: 1rem;
--text-base--line-height: calc(1.5 / 1);
--radius-sm: 0.25rem;
--default-transition-duration: 150ms;
--default-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
--default-font-family: var(--font-sans);
--default-mono-font-family: var(--font-mono);
--color-primary: oklch(0.57 0.203362 257.1706);
@@ -214,9 +212,6 @@
.mb-4 {
margin-bottom: calc(var(--spacing) * 4);
}
.contents {
display: contents;
}
.flex {
display: flex;
}
@@ -232,12 +227,6 @@
.w-full {
width: 100%;
}
.border-collapse {
border-collapse: collapse;
}
.resize {
resize: both;
}
.items-center {
align-items: center;
}
@@ -257,10 +246,6 @@
margin-inline-end: calc(calc(var(--spacing) * 4) * calc(1 - var(--tw-space-x-reverse)));
}
}
.border {
border-style: var(--tw-border-style);
border-width: 1px;
}
.bg-gray-200 {
background-color: var(--color-gray-200);
}
@@ -288,18 +273,6 @@
.text-white {
color: var(--color-white);
}
.underline {
text-decoration-line: underline;
}
.outline {
outline-style: var(--tw-outline-style);
outline-width: 1px;
}
.transition {
transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, --tw-gradient-from, --tw-gradient-via, --tw-gradient-to, opacity, box-shadow, transform, translate, scale, rotate, filter, -webkit-backdrop-filter, backdrop-filter, display, visibility, content-visibility, overlay, pointer-events;
transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));
transition-duration: var(--tw-duration, var(--default-transition-duration));
}
.hover\:text-gray-400 {
&:hover {
@media (hover: hover) {
@@ -421,22 +394,10 @@ hr {
inherits: false;
initial-value: 0;
}
@property --tw-border-style {
syntax: "*";
inherits: false;
initial-value: solid;
}
@property --tw-outline-style {
syntax: "*";
inherits: false;
initial-value: solid;
}
@layer properties {
@supports ((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b)))) {
*, ::before, ::after, ::backdrop {
--tw-space-x-reverse: 0;
--tw-border-style: solid;
--tw-outline-style: solid;
}
}
}

View File

@@ -21,8 +21,14 @@ router.get('/', async function(req, res, next) {
*/
router.get('/:id', async function(req, res, next) {
const siteId = req.params.id;
let site = null;
const site = await siteModel.getById(siteId);
try {
site = await siteModel.getById(siteId);
} catch (error) {
console.error('Error fetching site by ID:', error);
return res.status(400).send('Error fetching site: ' + error.message);
}
if (!site) {
return res.status(404).send('Site not found');
@@ -31,22 +37,52 @@ router.get('/:id', async function(req, res, next) {
}
});
/**
* GET site by domain name.
*
* Returns a specific site by its domain name in JSON format.
*/
router.get('/domain/:domain', async function(req, res, next) {
const domainName = req.params.domain;
let sites = null;
try {
sites = await siteModel.getByDomainName(domainName);
} catch (error) {
console.error('Error fetching site by domain name:', error);
return res.status(400).send('Error fetching site: ' + error.message);
}
console.log('Site found:', sites);
if (!sites || sites.length === 0) {
return res.status(404).send('Site not found');
} else {
res.json(sites[0]); // Return the first match
}
});
/**
* POST create a new site.
*
* Creates a new site with the provided domain name.
*
* // TODO: Implement validation for domain name format
* // TODO: Implement error handling for duplicate domains
* // TODO: Ability to add additional site properties (e.g., name, description)
*/
router.post('/add/:domain', function(req, res, next) {
const domain = req.params.domain;
const newSite = siteModel.insert(domain);
router.post('/add', async function(req, res, next) {
const domain = req.body.domain;
let newSite = null;
// insert method passes a lot of validation errors to the caller
try {
newSite = await siteModel.insert(domain);
} catch (error) {
console.error('Error creating site:', error);
return res.status(400).send('Error creating site: ' + error.message);
}
if (!newSite) {
return res.status(400).send('Error creating site');
res.status(400).send('Error creating site');
} else {
res.status(201).json(newSite);
}

View File

@@ -6,7 +6,7 @@
<ul>
<% for (let i = 0; i < sites.length; i++) { %>
<li><%= sites[i].name %></li>
<li><%= sites[i].domain_name %></li>
<% } %>
</ul>
</article>