Compare commits
9 Commits
main
...
feature/in
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f86bfee3f3 | ||
|
|
57c393d939 | ||
|
|
f28328dcc4 | ||
|
|
b9967a8e66 | ||
|
|
512d18ec23 | ||
|
|
c364e31ee3 | ||
|
|
061f9121b9 | ||
|
|
1ef5815f65 | ||
|
|
f9710d4387 |
26
.github/workflows/todos.yml
vendored
26
.github/workflows/todos.yml
vendored
@@ -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
|
||||
@@ -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
13
helpers/utils.js
Normal 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
|
||||
};
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
router.post('/add', async function(req, res, next) {
|
||||
const domain = req.body.domain;
|
||||
let newSite = null;
|
||||
|
||||
const newSite = siteModel.insert(domain);
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user